我正在嘗試從物件“Wheel1”中的腳本“WheelHandler”中獲取變數“isOffRoad”。我收到錯誤訊息:
Assets\Scripts\CarControler.cs(53,13):錯誤 CS1061:“GameObject”不包含“WheelHandler”的定義,并且找不到接受“GameObject”型別的第一個引數的可訪問擴展方法“WheelHandler”(是您缺少 using 指令或程式集參考?)
提前致謝。
編輯:isOffRoad 是公開的。
public GameObject Wheel1;
void Update()
{
if(Wheel1.WheelHandler.isOffRoad == true)
{
Debug.Log("offroad");
}
}
uj5u.com熱心網友回復:
您需要使用GetComponent<>()方法訪問您的組件。
在你的情況下,那將是Wheel1.GetComponent<WheelHandler>().isOffRoad
另外不建議在更新回圈中訪問組件。最好將其快取在欄位中。
uj5u.com熱心網友回復:
試試這個:
if (Wheel1.GetComponent<WheelHandler>().isOffRoad))
{
// do something..
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/482426.html
上一篇:將雙引號添加到串列以顯示在標簽中
