Unity 5.0 Roll-a-Ball教程中的NullReferenceException

时间:2015-04-09 12:51:04

标签: c# unity3d game-physics

不重复

It not duplicate question as it is not asking what is a NullPointerException, But putting a code that raises this error & but tutorial on unity website where it is taken from doesn't have this issue

我是Unity 3D的首发。我正在做团结滚球教程。当我编写脚本移动球时发生以下错误。

Unity 5.0,Windows 7

EXCEPTION

NullReferenceException
    UnityEngine.Rigidbody.AddForce (Vector3 force) (at C:/buildslave/unity/build/artifacts/generated/common/modules/NewDynamics.gen.cs:706)
    PlayerController.FixedUpdate () (at Assets/Scripts/PlayerController.cs:20)

SCRIPT

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

    // 
    void Start () {
    }

    // Initialization
    void FixedUpdate () {


        float moveHorizontal = Input.GetAxis ("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");

        Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

        Rigidbody role = new Rigidbody ();
        role.AddForce (movement);
    }
}

0 个答案:

没有答案