我刚刚开始学习unity 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);所以你实际上可以阅读文本。我希望有人能帮助我!
使用 Coroutine(据我所知这是 Unity3D 代码):
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);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)