目录
贪吃蛇资源包下载:传送门
🟥 实现贪吃蛇的主要API
1️⃣ 获取EasyTouch当前手势
Gesture currentGesture = EasyTouch.current;
2️⃣ 判断当前手势方向
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);
}
🟨 可能出现的BUG
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
大家还有什么问题,欢迎在下方留言!
如果你有 技术的问题 或 项目开发
都可以加下方联系方式
和我聊一聊你的故事🧡
本文含有隐藏内容,请 开通VIP 后查看