UnassignedReferenceException:尚未分配'MoveAround'的变量bullitPrefab。 Unity3D

时间:2013-02-06 06:13:53

标签: unity3d

我正在从头开始在Unity 3D中制作游戏。

我收到错误

UnassignedReferenceException:尚未分配'MoveAround'的变量bullitPrefab。 您可能需要在检查器中分配MoveAround脚本的bullitPrefab变量。 UnityEngine.Object.Internal_InstantiateSingle(UnityEngine.Object数据,Vector3 pos,Quaternion rot)(在C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:44) UnityEngine.Object.Instantiate(UnityEngine.Object original,Vector3 position,Quaternion rotation)(at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:53) MoveAround.Update()(在Assets / MoveAround.js:22)

我在以下代码中收到错误

enter code here

var speed = 3.0;
var rotateSpeed = 3.0;
var bullitPrefab:Transform;

function Update ()
{

var controller : CharacterController = GetComponent(CharacterController);

//Rotate around y - axis
transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);

//Move forward / bacward
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis("Vertical");
controller.SimpleMove(forward * curSpeed);

if(Input.GetButtonDown("Jump"))
{
    var bullit = Instantiate(bullitPrefab, gameObject.Find("spwanPoint").transform.position, Quaternion.identity);
}

}

@script RequireComponent(CharacterController)

这是教程的链接 http://www.youtube.com/watch?v=wfpZ7_aFoko&list=PL11F87EB39F84E292

1 个答案:

答案 0 :(得分:1)

将脚本附加到Unity3d中的对象时,您应该在对象资源管理器中看到公共变量。确保将bullitPrefab拖到该脚本,以便Unity3d知道在bullitPrefab中使用哪个预制件。它现在说(无),但它应该是bullitPrefab