Unity. Function call after a certain period of time

China☆狼群 提交于 2019-12-01 19:19:14

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");
        }
    }
}

try

StartCoroutine(SomeFunctionAfterSomeTime);

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!