How to make a delay with C# in Unity3D?

后端 未结 3 918
北海茫月
北海茫月 2021-01-26 02:14

I just started to learn c# in unity. I followed a tutorial, but i wanna add some things.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

pub         


        
3条回答
  •  Happy的楠姐
    2021-01-26 02:35

    Use Coroutine (as I see this is Unity3D code):

    void OnTriggerEnter(Collider other) 
        {
            if (other.gameObject.CompareTag ( "Pick Up"))
            {
                other.gameObject.SetActive (false);
                count = count + 1;
                StartCoroutine(SetCountText ());
            }
        }
    
        IEnumerator SetCountText ()
        {
            countText.text = "Count: " + count.ToString ();
            if (count >= 1)
            {
                winText.text = "You Win!";
                yield return new WaitForSeconds(1f);
                Application.LoadLevel(1);
            }
        }
    

提交回复
热议问题