6

How can I make an object invisible (or just delete) after a certain period of time? Use NGUI.

My example (for changes):

public class scriptFlashingPressStart : MonoBehaviour  
{   
    public GameObject off_Logo;
    public float dead_logo = 1.5f;

    void OffLogo()  
    {       
        off_Logo.SetActive(false);  
    }

    //function onclick button
    //remove item after a certain time after pressing ???
    void press_start()
    {
        InvokeRepeating("OffLogo", dead_logo , ...);
    }
}
derHugo
  • 83,094
  • 9
  • 75
  • 115

3 Answers3

4

Use Invoke rather than InvokeRepeating. check Invoke function here

 public class scriptFlashingPressStart : MonoBehaviour  
    {   
        public GameObject off_Logo;
        public float dead_logo = 1.5f;
        bool pressed = false;

    void OffLogo()  
    {       
       //do anything(delete or invisible)
        off_Logo.SetActive(false);
         pressed = false;  
    }

   //use Invoke rather than InvokeRepeating
    void press_start()
    {
        if(!pressed)
        {
          pressed = true;
          Invoke("OffLogo", dead_logo);
        }
        else
        {
          Debug.Log("Button already pressed");
        }
    }
}
Dasu
  • 433
  • 6
  • 16
2

try

StartCoroutine(SomeFunctionAfterSomeTime);

IEnumerator SomeFunctionAfterSomeTime()
{
    ... //Your own logic
    yield return new WaitForSeconds(SomeTime);
}
David
  • 15,894
  • 22
  • 55
  • 66
1

You can destroy an object in a given time by simply calling Destroy.

public static void Destroy(Object obj, float t = 0.0F);

Parameters

  • obj The object to destroy.
  • t The optional amount of time to delay before destroying the object.

See http://docs.unity3d.com/Documentation/ScriptReference/Object.Destroy.html

jparimaa
  • 1,964
  • 15
  • 19