- Home /
How do I go about using Hit.Test?
Hi,
I have come across a problem...
I have an empty game object, with a GUI Texture for a button to shoot
I have another script that does shooting
So far, I can't seem to use hit test to determine that Im pressing that button. If i tap the screen anywhere, the shooting works.
void Update ()
{
Touch touch;
if(Input.touchCount > 0)
{
touch = Input.touches[0];
if (touch.phase == TouchPhase.Began)
targetTex.texture = hoverTex; //swap texture
if(moveCtrl.facingRight)
{
//shoot
}
else
{
//shoot
}
}
if(Input.touchCount < 0)
{
touch = Input.touches[0];
if (touch.phase == TouchPhase.Ended)
targetTex.texture = normalTex; //swap texture back
}
I tried using guiTexture.Hitest but then it was telling me there is no gui.texture present because I am using an empty game object to determine where I am shooting from
How will I go about this? Is there any other way to do this?
Thanks
Comment
Best Answer
Answer by koray1396 · Mar 18, 2014 at 06:51 PM
Can you check this?
public GUITexture shootButton; // define your GUITexture from editor
if(shootButton.HitTest(touch.position))){ // add before if (touch.phase == TouchPhase.Began)
//shoot
}