- Home /
How to add touch input for mobile devices using unity?
Answer by Ekta-Mehta-D · Oct 04, 2013 at 07:37 AM
You can use Input.GetMouseButtonDown(0) ..
example :
if (Input.GetMouseButtonDown(0))
{
//code
}
You can go to this link for more detail
http://docs.unity3d.com/Documentation/ScriptReference/Input.GetMouseButtonDown.html
And you can also use Input.GetTouch..
You can go to this link for more detail
http://docs.unity3d.com/Documentation/ScriptReference/Input.GetTouch.html
Please do check mark if you find my answer useful.. Enjoy..
Answer by citizen_rafiq · Oct 04, 2013 at 10:35 AM
http://answers.unity3d.com/questions/527469/smooth-move-with-gui-button.html
if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) { foreach (Touch touch in Input.touches) { if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) { if (_joystickIndex==touch.fingerId){ _joystickIndex=-1; _enaReset=true; } }
if(_joystickIndex==touch.fingerId){ OnTouchDown(touch.position); } if (touch.phase == TouchPhase.Began) { if (((Vector2)touch.position - _joystickCenter).sqrMagnitude < Mathf.Pow((zoneRadius+touchSizeCoef/2),2)){ _joystickIndex = touch.fingerId; } } }
UpdateJoystick(); if(_enaReset){ ResetJoystick(); } }