Doesn't work

I have been trying to build my project but I get this error repeatedly

using Microsoft.Win32;
using System.ComponentModel;
using UnityEngine;
public class Moviment : MonoBehaviour
{
public Rigidbody Player;
public GameManager Gm;
public Pause pausa;
public float sideForce = 2000f;
public bool GameEnded;
void FixedUpdate(){
GameEnded = Gm.GetComponent (“GameHasEnded”); //the error is here
if (GameEnded == false && pausa.IsPaused == false)
{
if (Input.GetKey(“a”)){
Player.AddForce(-sideForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey(“d”))
{
Player.AddForce(sideForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if(Player.position.y < -0.1f){
FindObjectOfType().EndGame();
}
}
if(FindObjectOfType().IsPaused == true)
{
GetComponent().velocity = Vector3.zero;
GetComponent().angularVelocity = Vector3.zero;
}
}
}

And one of the errors is :
NullReferenceException: Object reference not set to an instance of an object
at Moviment.FixedUpdate () [0x00001] in Assets\Scripts\Movement.cs:13

In Unity works perfectly but when I build nope

Thanks in advice

@centsuej

Just an educated guess here…

Double-check that you dragged/assigned a GameObject with a Rigidbody attached to it on the Player variable of this script in the Inspector of the Unity Editor.

I suspect that Player is null because it’s not assigned anything.

1 Like

Some notes on how to fix a NullReferenceException error in Unity3D

  • also known as: Unassigned Reference Exception
  • also known as: Missing Reference Exception

http://plbm.com/?p=221

The basic steps outlined above are:

  • Identify what is null
  • Identify why it is null
  • Fix that.

Expect to see this error a LOT. It’s easily the most common thing to do when working. Learn how to fix it rapidly. It’s easy. See the above.

1 Like

Sorry my English isn’t really good :“)
And thats not the error, thanks :”)

The problem is fix that:")