Question by
Unity3dGameDevelopment · Jul 22, 2017 at 10:19 PM ·
androidunity 5touch controls
i want to move object only when i swipe on screen not when touch, Unity 2d Android
I want to move object in Unity2D when i swipe on screen and touch should not effect on my object. please tell me code for that how i can do that for Android Unity2D game. Thanks I have tried this but after swipe when i again try to swipe object, object suddenly moves towards my finger touch, so i want to stop that, i should remains here where it is and i can swipe it again.
void Update () {
foreach (Touch touch in Input.touches) {
Debug.Log("Touching at: " + touch.position);
if (touch.phase == TouchPhase.Began) {
Debug.Log("Touch phase began at: " + touch.position);
} else if (touch.phase == TouchPhase.Moved) {
Debug.Log("Touch phase Moved");
Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
pos = Input.mousePosition - pos;
float ang = Mathf.Atan2(pos.y, pos.x) *Mathf.Rad2Deg - 0.0f;
transform.rotation = Quaternion.AngleAxis(ang, Vector3.forward);
} else if (touch.phase == TouchPhase.Ended) {
Debug.Log("Touch phase Ended");
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Vector3.back not working 2 Answers
How to move FPS camera in Android using Touch in Unity android? 0 Answers
Play Store with Unity Personal 1 Answer
[AdMob][Android] Re-Packing error 0 Answers