- Home /
object reference is required to access non-static member 'GameManager.CompleteLever()'
I am trying to follow one online tutorial to make a simple game. and I am getting this error object reference is required to access non-static member 'GameManager.CompleteLever()'
using UnityEngine; using System.Collections;
public class PlayerMovement : MonoBehaviour { public float moveSpeed; private Vector3 input; private Vector3 spawn; public float maxSpeed; public GameObject deathParticles; void Start () { spawn = transform.position;
}
void Update () {
input = new Vector3(Input.GetAxisRaw("Horizontal"),0,Input.GetAxisRaw("Vertical"));
if (GetComponent<Rigidbody>().velocity.magnitude < maxSpeed)
{
GetComponent<Rigidbody>().AddForce(input * moveSpeed);
}
if (transform.position.y < -3)
{
Die();
}
}
void OnCollisionEnter(Collision other)
{
if (other.transform.tag == "Enemy")
{
Die();
}
}
void OnTriggerEnter(Collider other)
{
if (other.transform.tag == "Goal")
{
GameManager.CompleteLevel();
}
}
void Die()
{
Instantiate(deathParticles, transform.position, Quaternion.identity);
transform.position = spawn;
}
}
Answer by Malleck666 · Jul 09, 2016 at 05:21 PM
I assume GameManager is a script?
You'll need to create an instance of it and assign it in the inspector.
Your answer

Follow this Question
Related Questions
C#, "object reference not set to an instance of an object" 3 Answers
NullReferenceException: Object reference not set to an instance of an object 1 Answer
object reference not set to an instance of an but works with other script 1 Answer
UnityEngine.object Error 1 Answer
LitJson not working 0 Answers