我在我的场景中有一个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");
}
发布于 2012-04-14 17:49:33
试试下面的代码。通过游戏对象->创建其他->图形用户界面文本来创建GUIText对象。现在将其拖动到检查器面板中以下脚本的playerLives字段中。应该能行得通。
// the sound to play when the player is shot
public var shotSound:AudioClip;
public var GUIText playerLives;
// the number of lives
public var lives:int = 3;
function OnGUI ()
{
playerLives.Text = lives.ToString();
}
/**
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");
}
https://stackoverflow.com/questions/10141906
复制相似问题