nullreferenceexception:unity3d

Pra*_*shi 2 c# unity-game-engine

我刚开始在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)}

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

JoR*_*uss 5

你用一个小的"s"编写了start方法.因此Unity引擎不会调用它.

void Start()将起作用.注意资本"S".