本遊戲中的相機具有可以通過點擊其他模型進行更改的目標,然後是相機焦點,但下面的腳本是我目前爲止所獲得的目標當我點擊遊戲中的一個對象時,目標只是說沒有任何模型。C#unity使用光線投射命中信息更改變量
Ray toMouse = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
bool didHit = Physics.Raycast(toMouse, out hitInfo);
if (didHit)
{
if (hitInfo.collider.tag == "Cell" && Input.GetMouseButtonDown(0))
{
Debug.Log("Cell hit");
target = hitInfo.transform.Find(gameObject.name);
}
}
什麼是'gameObject.name'?似乎在這裏缺少一些代碼。 –
它的工作原理是將射線命中的對象的名稱轉換爲目標名稱。 – ryand444