我在Unity3D iOS遊戲中遇到了錯誤。UnityEngine.Object不包含GetComponent的定義
Assets/Scripts/Block/BlockMaker.cs(24,55): error CS1061: Type `UnityEngine.Object' does not contain a definition for `GetComponent' and no extension method `GetComponent' of type `UnityEngine.Object' could be found (are you missing a using directive or an assembly reference?)
這裏是代碼:
Block block = null;
for (int i = 0; i < listBlocks.Count; ++i)
{
if (listBlocks[i].GetComponent<Block>().type == type) {
block = Instantiate(listBlocks[i]).GetComponent<NormalBlock>(); // Error for this line
}
}
如何解決這個問題呢?已經Google搜索..沒有幫助我修復。
如果listBlocks是什麼類型? – Programmer
@Programmer public List listBlocks; –
iPhoneProcessor
腳本'Block'是否從MonoBehavior繼承?另外,腳本,你有內部的代碼,它是否從'MonoBehavior'繼承?如果你不介意,你的Unity版本是什麼? – Programmer