- Home /
time out between 2 touches android
I'm working on an android game and I got a simple code for touching a button with a tag. But when you touch the button it loads a new scene wich has another button on the exact same spot and when I try it out on my phone when I touch the first button the game loads the new scene and immediately touches the second button to so i can't touch the first button without touching the second one. I would like to have a delay that you can't touch anything for 1 second or so. Here is my code:` #pragma strict var knop : GameObject; var knopingedrukt : GameObject;
function Start () {
knop.renderer.enabled = true;
knopingedrukt.renderer.enabled = false;
}
function Update ()
{
if (Input.touchCount > 0)
{
var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit))
{
if(hit.collider.tag == "knop")
{
knop.renderer.enabled = false;
knopingedrukt.renderer.enabled = true;
Application.LoadLevel ("Classic");
}
}
}
}`
Answer by Mmmpies · Mar 03, 2015 at 10:47 AM
In the Start or Awake function set a float to equal Time.time + 1. When you check if the hit actually hits the button also check that Time.time is greater than the float.
var ButtonEnableTime : float = 0;
// Then in start
ButtonEnableTime = Time.time;
// Then in your check
if (hit.collider.tag == "knop" && Time.time > ButtonEnableTime)
Sorry for typos, on my phone.
Your answer
Follow this Question
Related Questions
Button reaction time problem 1 Answer
Create GUItexture Touch Button 1 Answer
Why this simple code doesnt work? 0 Answers
Quad not working as before 0 Answers
Button Touch for Android 2 Answers