版权声明:欢迎转载,转载请注明出处 https://blog.csdn.net/weixin_38239050/article/details/81913642
贪吃蛇资源包:下载
获取EasyTouch当前手势
Gesture currentGesture = EasyTouch.current;
判断当前手势是否为向上、下、左、右滑
currentGesture != null && currentGesture.swipe == EasyTouch.SwipeDirection.Up
currentGesture != null && currentGesture.swipe == EasyTouch.SwipeDirection.Down
currentGesture != null && currentGesture.swipe == EasyTouch.SwipeDirection.Left
currentGesture != null && currentGesture.swipe == EasyTouch.SwipeDirection.Right
贪吃蛇添加加速减速两种方法
1、挂载Button事件方法
写方法,挂载到EasyTouch Button的On Down()和On Up()事件上去
public void ButtonDown()
{
if (MainUIController.Instance.isPause == false && isDie == false)
{
CancelInvoke();
InvokeRepeating("Move", 0, velocity - 0.2f);
}
}
public void ButtonUp()
{
if (MainUIController.Instance.isPause == false && isDie == false)
{
CancelInvoke();
InvokeRepeating("Move", 0, velocity);
}
}
2、代码获取手势方法
//SpeedUpButton为Button的名字
if (ETCInput.GetButtonDown("SpeedUpButton") && MainUIController.Instance.isPause == false && isDie == false)
{
CancelInvoke();
InvokeRepeating("Move", 0, velocity - 0.2f);
}
if (ETCInput.GetButtonUp("SpeedUpButton") && MainUIController.Instance.isPause == false && isDie == false)
{
CancelInvoke();
InvokeRepeating("Move", 0, velocity);
}
Debug
EasyTouch的Button键或许或有bug,我们根据文档提示按步骤操作
If you found problems in the behavior of the buttons with ETCInput.GetButtonDown or ETCInput.GetButtonUp,please force the script execution order like this :
1- Open Script Execution Order (Edit => Project Settings => Script Execution Order)
2- Add ETCButton in first
3- Add yours scripts that use ETCInput.
即:任意一个脚本——Inspector——Script Execution Order——首先添加ETCButton,其次添加用到ETCInput的脚本——Apply