[Unity]GUI打字效果
public float letterPause = 0.2f;
public AudioClip sound;
private string word;
public string text;
void Start ()
{
word = text;
text = "";
}
void Update ()
{
if(Input.GetMouseButtonDown(0))
{
StartCoroutine("TypeText");
}
}
void OnGUI()
{
GUI.Label (new Rect(100,75,250,25),"Please answer my question,who am I?");
GUI.Box (new Rect(100,100,250,25),text);
}
IEnumerator TypeText()
{
foreach(char letter in word.ToCharArray())
{
text+=letter;
if(sound)
audio.PlayOneShot(sound);
yield return new WaitForSeconds(letterPause);
}
}
public AudioClip sound;
private string word;
public string text;
void Start ()
{
word = text;
text = "";
}
void Update ()
{
if(Input.GetMouseButtonDown(0))
{
StartCoroutine("TypeText");
}
}
void OnGUI()
{
GUI.Label (new Rect(100,75,250,25),"Please answer my question,who am I?");
GUI.Box (new Rect(100,100,250,25),text);
}
IEnumerator TypeText()
{
foreach(char letter in word.ToCharArray())
{
text+=letter;
if(sound)
audio.PlayOneShot(sound);
yield return new WaitForSeconds(letterPause);
}
}
留言
張貼留言