void Update() { if (stickActive) { bool touchFound = false; foreach (Touch t in Input.touches) { if (t.position.x >= Screen.currentResolution.width * minX && t.position.x <= Screen.currentResolution.width * maxX) { stickDelta = (t.position - startPos) / radius; if (stickDelta.magnitude > 1) { stickDelta.Normalize(); } touchFound = true; } } if (!touchFound) { stickActive = false; if (resetX) { stickDelta.x = 0.0f; } if (resetY) { stickDelta.y = 0.0f; } } } else if (Input.touchCount > lastTouchCount) { foreach (Touch t in Input.touches) { if (t.position.x >= Screen.currentResolution.width * minX && t.position.x <= Screen.currentResolution.width * maxX) { startPos = t.position; stickActive = true; rectTransform.position = startPos; } } } imgParent.color = imgStick.color = Color.Lerp(imgParent.color, stickActive ? new Color(1, 1, 1, 1) : new Color(1, 1, 1, 0), Time.deltaTime * fadeSpeed); stickTransform.position = startPos + stickDelta * radius; StaticInputData.SetAxis(axisX, stickDelta.x); StaticInputData.SetAxis(axisY, stickDelta.y); lastTouchCount = Input.touchCount; }
public float GetValue() { return(StaticInputData.GetAxis(axisName) * (invert ? -1 : 1)); }