在程式碼中獲得物體,改變屬性
阿新 • • 發佈:2019-02-12
gameObject.Find("wenzi").GetComponent(GUIText).guiText="";
#pragma strict
function Start () {
}
var sd:int;
var xm:int;
function Update () {
if(gameObject.transform.position.y<0)
{
//讀取Main Camera sheji指令碼中的變數xmshu
xm=gameObject.Find("Main Camera").GetComponent(sheji).xmshu++;
sd=gameObject.Find("Main Camera").GetComponent(sheji).sdshu++;
gameObject.Find("wenzi").GetComponent(GUIText).guiText="射彈數:"+sd+" 消滅數:"+xm;
if(xm>20)
{
gameObject.Find("wenzi").GetComponent(GUIText).guiText="恭喜過關!繼續努力!堅持學下去!";
gameObject.Find("Main Camera").GetComponent(sheji).enable=false;
}
Destory(gameObject);
}
}