从另一个脚本错误中获取变量

时间:2015-07-01 23:34:47

标签: c# unity3d nullreferenceexception

我的游戏类型无穷无尽,因此它随机生成了平台。 生成平台的块(“Quad”)需要随播放器一起移动,所以 我决定让他以与玩家相同的速度移动。

好吧,我在玩游戏时遇到了这个错误(块也没有移动):

  

NullReferenceException:对象引用未设置为对象的实例。

这是我的播放器代码:

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {

    //Floats iniciais.
    public float speed = 100f;
    public float maxSpeed = 10f;
    public float jumpPower = 50f;

    //Instaciando
    public Player player;
//rest of the code ...

这是产卵者代码:

using UnityEngine;
using System.Collections;

public class Spawner : MonoBehaviour {
    private Player player;
    private Rigidbody2D rb2d;

//Spawner mechanics Code... no need to write here.

  /// Problem-->
void FixedUpdate() {
  rb2d.AddForce (Vector2.right * player.maxSpeed);
  ///   Problem ends here-->    
}

0 个答案:

没有答案