12879人加入学习
(90人评价)
Unity2D 中级案例-甜品消消乐(Unity2017.2)

制作于2018年1月6日

价格 免费

MovedSweet脚本;拿到GameSweet sweet;

 

public void Move(int newX,int  newX)

 

新添加变量 移动 MoveComponent

判断是否移动的方法

 

[展开全文]

新建移动脚本并将其挂载到预制上。

 

(1)移动算法实现:

  • 将新位置的newX赋值给sweet.X。
  • 将新位置的newY赋值给sweet.Y。
  • 更新位置:sweet .transform.position = sweet .gameManager.CorrectPosition(newX, newY);

(2)在自定义基础脚本里面添加一些东西。

// 棋子移动组件
    private MovedChess movedComponent;
    public MovedChess MovedComponent
    {
        get
        {
            return movedComponent;
        }
    }
// 判断棋子是否可以移动
    public bool CanMove()
    {
        return movedComponent != null;
    }

在上方加一个判断,是否能够更改x,y的值。

public int X
    {
        get
        {
            return x;
        }

        set
        {
            if (CanMove())
            {
                x = value;
            }   
        }
    }
    public int Y
    {
        get
        {
            return y;
        }

        set
        {
            if (CanMove())
            {
                y = value;
            }
 
        }
    }

 

 

[展开全文]

授课教师

SiKi学院老师

课程特色

图文(1)
下载资料(1)
视频(49)

学员动态