資源加載的問題
using?System.Collections;
using?System.Collections.Generic;
using?UnityEngine;
public?class?tank?:?MonoBehaviour?{
????private?GameObject?Bullet;
????private?GameObject?bullet;
//?Use?this?for?initialization
void?Start?()?{
????????Bullet?=?Resources.Load("Bullet")?as?GameObject;
????}
//?Update?is?called?once?per?frame
void?Update?()?{
if(Input.GetButtonDown("Fire1"))
????????{
????????????bullet?=?Instantiate(Bullet);
????????????bullet.transform.parent?=?this.transform;
????????}
}
}28分鐘左右的地方在講資源加載,按照老師的操作來的,但是運行起來報錯
ArgumentException: The Object you want to instantiate is null.
UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:239)
UnityEngine.Object.Instantiate[GameObject] (UnityEngine.GameObject original) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:200)
tank.Update () (at Assets/Scripts/tank.cs:17)
2019-04-25
是不是沒把需要加載的預設物,放進Resources文件夾里
2018-07-14
文件夾"Resources"有沒有漏掉最后的"s"
2018-03-15
我出現同樣問題,檢查代碼和文件名暫無發現錯誤,難道是免費版本的 unity 不允許動態加載資源?
2018-01-23
會不會是名字不區分大小寫