效果图:
上代码:
public class TextFadeOut : MonoBehaviour {
public float speed = 0.5f;
Text text;
Color color;
void Start () {
text = GetComponent<Text>();
color = text.color;
}
void Update () {
if (gameObject.activeSelf)
{
color.a -= Time.deltaTime * speed;
text.color = color;
}
}
}
注意:两个Text——"Ready" "GO!" 都要挂上TextFadeOut脚本。并且两个Text,先禁用隐藏掉。
public class PrepareLevel : MonoBehaviour {
public GameObject GetReady;
public GameObject Go;
void Start () {
StartCoroutine(PrepareRoutine());
}
IEnumerator PrepareRoutine() {
yield return new WaitForSeconds(1f);
GetReady.SetActive(true);
yield return new WaitForSeconds(2f);
GetReady.SetActive(false);
Go.SetActive(true);
yield return new WaitForSeconds(1f);
Go.SetActive(false);
}
}
注意:创建一个空物体,名字改为GameController,然后将PrepareLevel 脚本挂在它上面。