actuy3798672
2018-01-15 22:26
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)
是不是没把需要加载的预设物,放进Resources文件夹里
文件夹"Resources"有没有漏掉最后的"s"
我出现同样问题,检查代码和文件名暂无发现错误,难道是免费版本的 unity 不允许动态加载资源?
会不会是名字不区分大小写
Unity 3D游戏开发之脚本系统
31744 学习 · 26 问题
相似问题