Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug error CS0120.GameManager

Discussion in 'Scripting' started by EnotVoxel, Jan 25, 2023.

  1. EnotVoxel

    EnotVoxel

    Joined:
    Jan 25, 2023
    Posts:
    2
    error CS0120: An object reference is required for the non-static field, method, or property 'Behaviour.enabled'

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3.  
    4. public class GameManager : MonoBehaviour
    5. {
    6.     public Movement M;
    7.     public float levelRestartDelay = 2f;
    8.  
    9.     public void EndGame()
    10.     {
    11.         Movement.enabled = false;
    12.  
    13.         Invoke("RestartLevel", levelRestartDelay);
    14.     }
    15.     void RestartLevel()
    16.     {
    17.         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    18.     }
    19. }
    20.  
     
  2. SF_FrankvHoof

    SF_FrankvHoof

    Joined:
    Apr 1, 2022
    Posts:
    780
    "Movement" is a Type, not an instance of a class.
    If you want to enable/disable the Movement-Class you're referring to in your script, look at "M" instead.
     
  3. EnotVoxel

    EnotVoxel

    Joined:
    Jan 25, 2023
    Posts:
    2
    Thank you very much