- Home /
Help with HitTest() for buttons
I am trying to use my guiText as buttons using HitTest() and touch position. But it says that UnityEngine.Touch is required to use the non static version of position. What do I need to do to fix this?
var a : GameObject;
if (a.guiText.HitTest(Touch.position)){
//do things
}
EDIT: added code
Answer by jahroy · Dec 18, 2011 at 08:58 PM
Touch is the name of the class that represents touch input.
To get the position of a specific touch, you need to get an actual instance of a Touch object.
The Input class contains an array of Touches that represents all the fingers touching the screen at any given moment.
To get the first one and store it in a variable you would do this:
var firstFinger : Touch = Input.GetTouch(0);
Note that arrays start at element zero.
You could also access the array directly like this (though I've never tried):
var firstFinger : Touch = Input.touches[0];
To print the position of the 2nd finger on the screen, you would do this:
Debug.Log("finger 2 pos: " + Input.GetTouch(1).position);
Your answer
Follow this Question
Related Questions
How do I go about using Hit.Test? 1 Answer
GuiTexture (Touch button) unfollow camera! 1 Answer
Rect.contains to replace gui 2 Answers
Problem with rect and touch 1 Answer
how to a make a touch button open a menu while finger is down? 1 Answer