Delaying GUITexture!!!

Hey :slight_smile: … How would i put a delay in this… to go in to more detail i want a delay just before my GuiTexture activates This is the code it all works but i want a delay off like 3 seconds befor it actully activates anybody know how to do this??..

var Aim : boolean = false;

var SnipeTexture : GUITexture;

function Update ()

{

if(Input.GetMouseButton(1))
{
   Aim = true;
}

if(Input.GetMouseButtonUp(1))

{
   Aim = false;
}

if(SnipeTexture == null)

   return;

if(Aim)
{
   SnipeTexture.enabled = true;
}
if(!Aim)
{
   SnipeTexture.enabled = false;
}

}

Thanks.

add this to your code:

// do something
yield WaitForSeconds(3.0); // wait for 3 seconds
// do something more...

Source

EDIT - C# Example:

using UnityEngine;
using System.Collections;

public class test : MonoBehaviour {

    bool calledDelay = false;
    bool doneDelay = false;

    IEnumerator Wait(float sec)
    {
        yield return new WaitForSeconds(sec);
        Debug.Log("3 seconds later");
        doneDelay = true;
    }

    void Update () {
        if (doneDelay)
            Debug.Log("Do something");
        else if (!calledDelay)
        {
            calledDelay = true;
            StartCoroutine(Wait(3f));
        }
    }
}

function WaitAndSnipe(bool onOff)
{
aim = onOff;
yield WaitForSeconds(3.0);
if(aim == onOff)
{
SnipeTexture.enabled = onOff;
}
}

Then, call it from Update inside of

if(Input.GetMouseButtonDown(1))
{
    StartCoroutine(WaitAndSnipe(true));
}

if(Input.GetMouseButtonUp(1))
{
    StartCoroutine(WaitAndSnipe(false));
}
var Aim : boolean = false;

var repeating : boolean = false;

var lastActivationTime;

var SnipeTexture : GUITexture;

function Update ()

{

if(Input.GetMouseButton(1))
{
   Aim = true;
   if (repeating == false)
   {
      lastActivationTime = Time.time;
      repeating = true;
   }
}

if(Input.GetMouseButtonUp(1))

{
   Aim = false;
   repeating = false;
}

if(SnipeTexture == null)

   return;

if(Aim && (Time.time - lastActivationTime > 3.0))
{
   SnipeTexture.enabled = true;
}

if(!Aim)
{
   SnipeTexture.enabled = false;
}

}