当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 甜品消消乐 03甜品的生成与基础脚本的编写

甜品消消乐 03甜品的生成与基础脚本的编写

2020年07月28日  | 移动技术网IT编程  | 我要评论

(1)甜品数组
// 甜品数组,使用二维存放生成的甜品,用于后续操作
private GameSweet[,] sweets;
(2)2层循环产生甜品

void Start () {
        sweets = new GameObject[xColumn, yRow];
        for (int x = 0; x < xColumn; x++)
        {
            for (int y = 0; y < yRow; y++)
            {
                //实例化游戏甜品  甜品已经放在字典中  所以可以通过游戏种类进行实例化
                sweets[x, y] = Instantiate(sweetPrefabDict[SweetsType.NORMAL], CorrectPositon(x, y), Quaternion.identity);
                sweets[x, y].transform.SetParent(transform);
            }
        }
    }

(3)自定义甜品类:为了对甜品进行操作(移动、消除、动画播放、自身属性)。因此写一个甜品的基础脚本
将甜品x,y位置,type类型设置为属性访问器,其中Type设置为只可以获取,不可修改
在这里插入图片描述
(4)自定义甜品类初始化

    public void Init(int _x,int _y,GameManager _gameManager,GameManager.SweetsType _type)
    {
        x = _x;
        y = _y;
        gameManager = _gameManager;
        type = _type;
    }

本文地址:https://blog.csdn.net/weixin_43992968/article/details/107608625

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网