我正在爲我的學校創建一個項目,直到現在它還是相當不錯的。我搜索了近一個小時的答案,仍然找不到任何東西(錯誤的標籤?)。顯示命中游戲對象的名稱
問題是我想顯示玩家正在用raycast擊中的物品的名稱。我試過這個,但可悲的是它不工作:
#pragma strict
var rayLength : int = 10;
private var inventory : Inventory;
private var guiShow : boolean = false;
var bush : GameObject;
var player : GameObject;
function Start()
{
inventory = GameObject.Find("First Person Controller").GetComponent(Inventory);
}
function Update()
{
var hit : RaycastHit;
var forward = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, forward, hit, rayLength))
{
if(hit.collider.gameObject.tag == "Wood")
{
guiShow = true;
if(Input.GetKeyDown("e"))
{
inventory.wood++;
Destroy(hit.collider.gameObject);
guiShow = false;
}
}
else if(hit.collider.gameObject.tag == "Sticks")
{
guiShow = true;
if(Input.GetKeyDown("e"))
{
inventory.stick++;
Destroy(hit.collider.gameObject);
guiShow = false;
}
}
else if(hit.collider.gameObject.tag == "BushFull")
{
guiShow = true;
bush = (hit.collider.gameObject);
if(Input.GetKeyDown("e"))
{
inventory.berry += 5;
bush.GetComponent(BushController).berriesTaken = true;
guiShow = false;
}
}
else
{
guiShow = false;
}
}
else
{
guiShow = false;
}
}
function OnGUI()
{
if(guiShow == true)
{
GUI.Box(Rect(Screen.width/2, Screen.height/2, 100, 25), "Pick up" + hit.collider.gameObject);
}
}
如果有人知道答案 - 請幫助我。提前致謝!
請不要加標題中的標籤,Unity的「JavaScript」其實不是JavaScript,而是UnityScript – LearnCocos2D 2015-02-06 10:54:42
哦,好的。對不起 - 不會再發生。 – Fiffe 2015-02-06 10:56:37