using UnityEngine; using System.Collections; public class JoystickController : MonoBehaviour { private Joystick mJoystick; private float mSpeed=7.5F; void Start () { //获取Joystick mJoystick=GameObject.Find("UnityJoystick").GetComponent<Joystick>(); } void Update () { //获取摇杆响应值 float mX=mJoystick.position.x; float mY=mJoystick.position.y; //移动角色 if(mX!=0||mY!=0) { Vector3 mPos=new Vector3(transform.position.x+mX,transform.position.y, transform.position.z+mY); transform.LookAt(mPos); //移动玩家的位置(按朝向位置移动) transform.Translate(Vector3.forward * Time.deltaTime * 5F); //播放奔跑动画 animation.Play("Run"); }else { animation.Play("idle"); } } }