- Home /
touch input
hi im testing my game with an iphone and have noticed that mouse down works fine on the device, but i want to use touch as i could be touching two things at any one time.
basically i have up,down,left,right as gui buttons and need to be able to say touch up and left at the same time,
will mousedown work for this or do i need to use touch. if so what is the proper code to say if i touch this gui, then do whatever as i tried a few things and nothing is working.
are you using OnGUI and GUI.button? Reason I ask is that using Unity's GUI system first of all on a mobile device is a huge no-no. Second of all, mouse down will not work, you will have to use Touch input to detect multi-touch on mobile devices.
well i tried on gui but no response unless i used on mouse down, i would like to if i cant use gui mark out an area where if i touch changes the gui texture and does the action.
so pretty much faking me pressing on gui, but visually looks as if i am
Answer by reptilebeats · Jan 19, 2012 at 12:51 AM
this is the sort of code i was looking for nice and simple...
function Update(){
if (Input.touchCount >0){
var touch : Touch = Input.touches[0];
}
if(touch.phase == TouchPhase.Stationary && guiTexture.HitTest(touch.position)){
Debug.Log("hi");
}
}
Answer by kaimelar · Jan 17, 2012 at 08:44 PM
Input.touchCount = > You can check how much finger on the screen Ex:
if(Input.touchCount == 2){
Debug.Log("Two finger on the screen");
Input.GetTouch(0); => you can get touch data 0 or 1;Ex:
Touch t0 = Input.GetTouch(0);
Vector3 t0Pos = new Vector3(t0.deltaPosition.x, t0.deltaPosition, 0);
Debug.Log(t0Pos);
t0.phase => This is your finger status Ex:
if(t0.phase == TouchPhase.Moved)
Debug.Log("Your finger is moving now");
These are important function.If you any problem, ask again here.
Your answer
Follow this Question
Related Questions
OnMouseDown is checked when build for Android 2 Answers
A node in a childnode? 1 Answer
Raycast based on a Rect? 1 Answer
Touch / Mouse tracing 1 Answer
How to select an object with TOUCH and change its animation 2D 1 Answer