【发布时间】:2012-04-25 21:08:48
【问题描述】:
我的场景中有一个 GUI 文本对象,我希望它显示我为该剧留下的剩余生命。由于某种原因,我似乎无法让它工作。我有下面的代码,有人可以帮我吗?!
// the sound to play when the player is shot
public var shotSound:AudioClip;
// the number of lives
public var lives:int = 3;
/**
Player has been shot
*/
function Shot ()
{
// play the shot audio clip
audio.PlayOneShot(shotSound);
// reduce lives
lives--;
// reload the level if no lives left
if (lives == 0)
{
// destroy the crosshair
Destroy(GetComponent(CrossHair));
// add the camera fade (black by default)
iTween.CameraFadeAdd();
// fade the transparency to 1 over 1 second and reload scene once complete
iTween.CameraFadeTo(iTween.Hash("amount", 1, "time", 1, "oncomplete", "ReloadScene", "oncompletetarget", gameObject));
}
}
/**
Reload the scene
*/
function ReloadScene()
{
// reload scene
Application.LoadLevel("MainMenu");
}
【问题讨论】:
-
怎么不行?详细信息会帮助那些想要提供帮助的人。
-
场景上的GUI文字基本不会更新。它保持它设置的通用文本。我在更新函数中使用了 (guiText.text = "Lives Remaining: "+lives;) 代码,并使其成为 GUI 文本的一个组件,但它似乎不起作用?
-
您是否有机会发布您尝试过的一些(任何)代码?我什至没有在这段代码中看到
update(),也没有看到对guiText的任何引用。也许我遗漏了一些东西,但我认为如果有人要帮助这个,我需要更多信息。 -
代码中没有更新功能,我需要把它放进去然后把 (guiText.text = "Lives Remaining: "+lives;) 放进去吗?我想我确实尝试过,但它似乎没有用。
标签: user-interface text unity3d