统一。一段时间后的函数调用

时间:2014-02-06 09:15:15

标签: c# unity3d unityscript ngui

如何在一段时间后使对象不可见(或只是删除)? 使用NGUI。

我的例子(更改):

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 , ...);
    }
}

3 个答案:

答案 0 :(得分:3)

使用Invoke而不是InvokeRepeating。 检查调用函数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");
        }
    }
}

答案 1 :(得分:1)

尝试

StartCoroutine(SomeFunctionAfterSomeTime);

IEnumerator SomeFunctionAfterSomeTime()
{
    ... //Your own logic
    yield return new WaitForSeconds(SomeTime);
}

答案 2 :(得分:0)

您可以通过简单地调用Destroy来销毁给定时间内的对象。见http://docs.unity3d.com/Documentation/ScriptReference/Object.Destroy.html