void Update() { move.Set(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0); //Debug.Log(move); move = move.normalized * speed * Time.deltaTime; trans.Translate(move, Space.World); }
public static Touch GetTouch(int id) { #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL return(MakefakeTouchOnPc()); #endif #if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE || UNITY_IOS || UNITY_WP_8 || UNITY_WP_8_1) return(Input.GetTouch(id)); #endif }
int GetAnalogTouchFingerIDInsideArea(int id) { #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL return(id); #endif #if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE || UNITY_IOS || UNITY_WP_8 || UNITY_WP_8_1) if (id == -1) { return(-1); } return(Input.GetTouch(id).fingerId); #endif }
public static Touch GetTouchByFingerID(int fingerID) { #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL return(MakefakeTouchOnPc()); #endif #if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE || UNITY_IOS || UNITY_WP_8 || UNITY_WP_8_1) for (int i = 0; i < Input.touchCount; i++) { if (Input.GetTouch(i).fingerId == fingerID) { return(Input.GetTouch(i)); } } return(new Touch()); #endif }
int GetAnalogFingerIDInsideArea() { #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL if ((UnityEngine.Input.GetMouseButtonDown(0) || UnityEngine.Input.GetMouseButtonUp(0) || UnityEngine.Input.GetMouseButton(0)) && IsInsideArea(UnityEngine.Input.mousePosition)) { return(0); } else { return(-1); } #endif #if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE || UNITY_IOS || UNITY_WP_8 || UNITY_WP_8_1) for (int i = 0; i < Input.touchCount; i++) { if (IsInsideArea(Input.GetTouch(i).position)) { return(i); } } return(-1); #endif }
void Update() { if (_devOrientation != UnityEngine.Input.deviceOrientation || ScreenPixels.x != Screen.width || ScreenPixels.y != Screen.height) { RecalculateLayout(); } lastFrameNormalizedAxis = NormalizedAxis; //SIMULATED MOBILE VIRTUAL JOYSTICK KNOB ON EDITOR AND EFFETIVE MOBILE VIRTUAL JOYSTICK KNOB if (TouchAbstraction.TouchCont > 0) { if (Released) { InsideAreaFingerId = GetAnalogFingerIDInsideArea(); } if (InsideAreaFingerId != -1) { AnalogTouch = TouchAbstraction.GetTouchByFingerID(InsideAreaFingerId); if (Released) { if (AnalogTouch.phase == TouchPhase.Began) { Released = false; TouchBegan(AnalogTouch.position); } } else { if (AnalogTouch.phase == TouchPhase.Moved || AnalogTouch.phase == TouchPhase.Stationary) { TouchMove(AnalogTouch.position); } else if (AnalogTouch.phase == TouchPhase.Ended) { TouchEnd(); } } } else { Released = true; } } else { InsideAreaFingerId = -1; Released = true; } if (Released == true) { rectTransform.position = Vector2.Lerp(transHandle.position, startPosition, ReturnSpeed * Time.unscaledDeltaTime); } Input.SetAxisMobile(HorizontalAxis, NormalizedAxis.x); Input.SetAxisMobile(VerticalAxis, NormalizedAxis.y); if (Mathf.Abs(lastFrameNormalizedAxis.x) < 0.2f && NormalizedAxis.x != 0f) { Input.PressButtonDownMobile(HorizontalAxis); } if (Mathf.Abs(lastFrameNormalizedAxis.y) < 0.2f && NormalizedAxis.y != 0f) { Input.PressButtonDownMobile(VerticalAxis); } }