我剛開始學習統一的c#。我跟着一個教程,但我想補充一些東西。如何在Unity3D中使用C#進行延遲?
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
void Start()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText();
winText.text = "";
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText();
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString();
if (count >= 1)
{
winText.text = "You Win!";
Application.LoadLevel(1);
}
}
}
我想在winText.text =「You Win!」之間做一個延遲。 和Application.LoadLevel(1);所以你可以真正閱讀文本。我希望有人能幫助我!
Thread.sleep代碼(50); –
相關:http://stackoverflow.com/q/5449956/3273247 – dbrad
這應該會幫助你 – dbrad