EasyTouch的joystick跟随鼠标
1 using UnityEngine; 2 using System.Collections; 3 4 public class JoystickPosControll : MonoBehaviour 5 { 6 7 public EasyJoystick m_EasyJoystick; 8 9 public Vector2 offset; 10 11 public Camera m_Camera; 12 13 public Vector2 bili; 14 15 private bool isFrist = true; 16 17 18 19 void OnPress(bool bPress) 20 { 21 if (isFrist && bPress) 22 { 23 isFrist = false; 24 25 Vector2 mousepos = Input.mousePosition; 26 27 mousepos.x += offset.x; 28 mousepos.y = -mousepos.y - offset.y; 29 30 mousepos = m_Camera.ScreenToViewportPoint(mousepos); 31 32 mousepos.x *= bili.x; 33 mousepos.y *= bili.y; 34 35 m_EasyJoystick.JoystickPositionOffset = mousepos; 36 37 } 38 else 39 { 40 isFrist = true; 41 m_EasyJoystick.JoystickPositionOffset = Vector2.zero; 42 } 43 } 44 45 }
时间: 2024-10-19 02:01:06