- Home /
(Android)If there are no touches on GUITexture
How do I see if there are no toches touching a GUITexture? Thanks in advance.
Answer by MadJohny · Dec 30, 2013 at 04:25 PM
should this be correct?
foreach (Touch touch in Input.touches) {
if (!guiTexture.HitTest(touch.position)) {
player.gameObject.layer = 0;
}
}
if (Input.touchCount == 0) {
player.gameObject.layer = 0;
}
Answer by baris150490 · Dec 30, 2013 at 04:33 PM
If there will be no touches on GUITexture what is the point of creating one?Tell us what you are trying to achieve and let us guide you.
first, you should have commented ins$$anonymous$$d of making an answer, then read my answer, and THEN, it's kinda obvious that there will be touches on the GUITexture(I said how do I see if there are no touches on it, if I ask this, obviously the player will be able to touch it), just not everytime
Obviously, GUITexture will do something when you TOUCH IT,if there is not it won't do anything and here you go your answer : there is no TOUCH on it..
Answer by Spinnernicholas · Dec 30, 2013 at 10:02 PM
You should create a bool value that stores if a touch occurred in the last frame.
bool isTouched = false;
//..............
void Update()
{
if(!isTouched)
{
//do something
}
//reset isTouched
isTouched = false;
}
//Or.....
void Update()
{
if(!isTouched)
{
//Not Touched
//do something
}
else
{
//Touched, Do Something
//reset isTouched
isTouched = false;
}
}
It requires you to have other scripts to handle touch detection. Do you not have touch detection working?
You don't want to re-ray cast for every object you have to detect touches on, so ins$$anonymous$$d, do it once.
You should have a script that raycasts from each touch and send messages to the objects the rays collide with. Let's call it OnTouch:
touchedObject.Send$$anonymous$$essage("OnTouch");
and then add this to the first script I gave you.
void OnTouch()
{
isTouched = true;
}
And tada, it all works.
Your answer
Follow this Question
Related Questions
Unity Vuforia video error 0 Answers
Android Keyboard Issues 0 Answers
Android GUI Button problem 2 Answers
Mobile - lingering touch even after finger lifts 0 Answers
What is 'off-screen touch input', what is 'SecondaryTouch'? 0 Answers