俄罗斯方块制作(未完成)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/*
 title:俄罗斯方块代码
 1、随机的显示方块
 2、显示的方块运行脚本
 3、碰到标签为a的,就随机克隆方块
 4、这里最多能横排可以放下11个方块
 5、先把所有方块的y坐标放到列表里
 6、如果列表里某个坐标的值一样的有11个说明要消除这一行
 */

public class Move : MonoBehaviour
{
    void i()
    {
        int a1 = Random.Range(1, 2);
        if (a1 == 1)
        {
            t.SetActive(true);
            l.SetActive(false);
        }
        if (a1 == 2)
        {
            t.SetActive(false);
            l.SetActive(true);
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        i();

    }

    bool right = false;
    bool left = false;
    bool rotate1 = false;
    bool down = false;
    bool d = false;

    public GameObject object1;
    public GameObject t;
    public GameObject l;
    public GameObject object2;


    List<float> y = new List<float>();

    // Update is called once per frame
    void Update()
    {

        Vector3 pos = transform.position;
        Vector3 rotate = transform.localEulerAngles;

        if (Input.GetKeyDown(KeyCode.LeftArrow)){left = true; } else { left = false; }
        if (Input.GetKeyDown(KeyCode.RightArrow)) { right = true; } else { right = false; }
        if (Input.GetKeyDown(KeyCode.UpArrow)) { rotate1 = true;} else { rotate1 = false; }
        if (Input.GetKeyDown(KeyCode.DownArrow)) { down = true; } else { down = false; }

        if(left){ pos.x -= 7 * Time.deltaTime;}
        if (right){ pos.x += 7 * Time.deltaTime; }
        if (rotate1) { rotate.z -= 90; }
        if (down) { pos.y -= 5 * Time.deltaTime; }
        
        if (d)
        {
            
            if (gameObject.name == "T")
            {
                object1.SetActive(true);
                object1.transform.position = pos;
                GameObject a = Instantiate(object1, pos, transform.rotation);
                object1.SetActive(false);
            }
            if(gameObject.name == "L")
            {
                object2.SetActive(true);
                object2.transform.position = pos;
                GameObject a = Instantiate(object2,pos, transform.rotation);
                object2.SetActive(false);
            }

            i();

            pos.y = 4.66f;
            transform.position = pos;
            d = false;
        }

        int p = 0;
        int u = 1;
        for(int i = 0;i < y.Count-1;i++)
        {          
            if(y[i] == y[u])
            {
                p++;
            }
            u += 1;
            if (p > 4)
            {
                Debug.Log("消除一行");
                p = 0;
            }
        }

        transform.position = pos ;
        transform.localEulerAngles = rotate;
        
    }


    void OnCollisionEnter2D(Collision2D e) {
        if(e.gameObject.tag == "a" && gameObject.tag == "a")
        {
            

            Transform[] myTransforms = GetComponentsInChildren<Transform>();
            foreach (var child in myTransforms)
            {
                Vector3 pos8 = child.position;
                y.Add(pos8.y);
                Debug.Log(pos8.y);
            }
            d = true;
        }
    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值