using UnityEngine; using System.Collections; using UnityEngine.UI; public class JoystickViewController : MonoBehaviour { private Vector2 _axisValue; public RectTransform axisView; public RectTransform axisViewParent; public void SetAxis(float x, float y){ _axisValue.x = Mathf.Clamp(x, -1.0f, 1.0f); _axisValue.y = Mathf.Clamp(y, -1.0f, 1.0f); if (_axisValue.sqrMagnitude > 1.0f) { _axisValue.Normalize (); } float parentWidth = axisViewParent.rect.width; float parentHeight = axisViewParent.rect.height; var pos = axisView.localPosition; pos.x = _axisValue.x * (parentWidth * 0.5f); pos.y = _axisValue.y * (parentHeight * 0.5f); axisView.localPosition = pos; } // Use this for initialization void Start () { } // Update is called once per frame void Update () { } }