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;
}

}

1 Answer

1

I assume GameManager is a script?

You’ll need to create an instance of it and assign it in the inspector.

Uhm, what does your Update method has to do with the custom inspector? It's just a normal method, if you want to call it, call it. Unity won't call it for you as that class is not a MonoBehaviour. If you want to invoke Update when the new instance is created you can do: var inst = new OrderAction.materialss(); t.materials.Add(inst); inst.Update(); instead. Though if that method is ment only for initializing it should be named "Init()" or something like that.