小编Pra*_*shi的帖子

nullreferenceexception:unity3d

我刚开始在unity3d工作.
我有这堂课

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

    private Rigidbody rb;
    void start()
    {
        rb = GetComponent<Rigidbody>();
    }
        void FixedUpdate()
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");
        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
        rb.AddForce(movement); 
    }
}
Run Code Online (Sandbox Code Playgroud)

它显示一个错误:

NullReferenceException:Object Reference未设置为对象的实例.
line:11 {rb.AddForce(movement)}

如果有人知道问题是什么以及如何解决,请分享.

c# unity-game-engine

2
推荐指数
1
解决办法
145
查看次数

标签 统计

c# ×1

unity-game-engine ×1