有些时候我们只是想做一个简单的摇杆,所以大可不必使用插件,几句代码就能搞定
首先你已经导入NGUI
在UI界面倒入背景精灵 然后添加触发器
然后在精灵 上添加子精灵

然后再精灵上挂载脚本
添加如下方法
OnPress(bool isPress)//NGUI回调
{
this.isPress=isPress;
}
- {
-
- Vector2 touch=UICamera.lastTouchPosition;
-
- if (UICamera.lastTouchPosition.x > Screen.width / 2) return;
- touch-=new Vector2(141,141);
- float distance=Vector2.Distance(Vector2.zero,touch);
- if(distance>73)
- {
- touch=touch.normalized*73;
- button.localPosition=touch;
-
- }
- else
- {
- button.localPosition=touch;
- }
-
- int h=touch.x/73;
- int v=touch.y/73;
-
- }
NGUI制作摇杆
原文:http://www.cnblogs.com/daluo/p/5815696.html