【发布时间】:2014-06-04 18:39:58
【问题描述】:
我正在使用 smartfox server2x 在 unity3d 中进行多人协作。在这有2个脚本 a)game manager.cs 被拖入游戏对象 b)timer.js 脚本被拖入 guitext 。如何将此 guitext 添加到游戏对象中?当我尝试执行此操作时,我收到了类似
的错误“没有'GUIText'附加到“Game”游戏对象,但是一个 脚本正在尝试访问它。
您可能需要向游戏对象“Game”添加一个 GUIText。或者你的 脚本在使用之前需要检查组件是否被附加。”
这是一个脚本
#pragma strict
public var timeLeft:float = 10.0f;
public var IsTiming : boolean;
//public bool IsTiming = false;
public function Start () {
//IsTiming = false;
}
function test1(vr1:boolean)
{
IsTiming=true;
Debug.Log("enter33333333333"+IsTiming);
//gamemanager = this.GetComponent("GameManager");
}
function OnGUI()
{
Debug.Log("enter2222222222"+IsTiming);
if(GUI.Button(Rect(0, 70, 150, 25), 'counter'))
{
IsTiming = true;
}
if(IsTiming)
{
Debug.Log("enterzzzzzzzzzz");
timeLeft -= Time.deltaTime;
if (timeLeft <= 0.0f)
{
guiText.text = "You ran out of time";
guiText.text = "Time is over";
}
else
{
guiText.text = "Time left = " + timeLeft + " seconds";
}
}
}
如何将此脚本添加到游戏对象“游戏”中。
【问题讨论】:
标签: unity3d unityscript