-2

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

我收到一个错误

UnassignedReferenceException:'MoveAround' 的变量 BullitPrefab 尚未分配。您可能需要在检查器中分配 MoveAround 脚本的 BullitPrefab 变量。UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, Vector3 pos, Quaternion rot) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:44) UnityEngine.Object.Instantiate (UnityEngine.Object original , Vector3 位置, 四元数旋转) (在 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

4

1 回答 1

1

当您将脚本附加到 Unity3d 中的对象时,您应该在对象资源管理器中看到公共变量。确保将 BullitPrefab 拖到该脚本中,以便 Unity3d 知道要在bullitPrefab. 它现在显示 (None),但应该是bullitPrefab.

于 2013-02-06T07:44:09.340 回答