Easy Touch 摇感控制人物移动

Easy Touch 摇感控制人物移动

public class joystick : MonoBehaviour

    {

        public float Speed;             //定义速度

        private CharacterController CC; //定义人称控制器

         //代码启动

        private void OnDisable()

        {

             //启动调用OnMove,OnMoveEnd

            EasyJoystick.On_JoystickMove += OnMove;

            EasyJoystick.On_JoystickMoveEnd += OnMoveEnd;

        }

        private void OnDestroy()

        {

             //结束关闭OnMove,OnMoveEnd

            EasyJoystick.On_JoystickMove -= OnMove;

            EasyJoystick.On_JoystickMoveEnd -= OnMoveEnd;

        }

        private void Start()

        {

            CC = GetComponent<CharacterController>();//得到控制器

        }

        //触摸移动方法

        public void OnMove(MovingJoystick move)

        {

             //判断是否是Easy Touch 摇感

            if (move.joystickName != "New joystick")

            {

                return;

            }

             //定义前后左右移动

            float joyPositionX = move.joystickAxis.x;

            float joyPositionY = move.joystickAxis.y;

             //判断前后移动

            if (joyPositionY != 0 || joyPositionX != 0)

            {

                   //定义坐标

                Vector3 movePosition = new Vector3(joyPositionX, 0, joyPositionY);

                   //定义坐标增量

                Vector3 dir = transform.position + movePosition;

                   //面向方向

                transform.LookAt(dir);

                   //定位移动

                Vector3 moVector3 = transform.forward*Time.deltaTime*Speed;

                   //第一人称移动

                CC.Move(moVector3);

            }

        }

         //触摸移动方法结束

        public void OnMoveEnd(MovingJoystick move)

        {

           Debug.Log("触摸抬起")

        }

}

注:使用此方法,必须在导入Easy Touch插件之后进行,一般用于非PC端使用。

Easy Touch 摇感控制人物移动

上一篇:appium API接口


下一篇:Android Native内存泄漏检测方法