FindObjectOfType doesnt exist?

Updated on December 23, 2017 in [A] Brackeys Courses
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on December 22, 2017

Hey, i am a pretty new developer and was just following along brackeys tuorial on how to make a video game.

i wanted to call a function from another script using FindObjectOfType as he has done in his tutorial, however  in my project i get the error:

Assets/Scripts/PlayerMovement.cs(40,13): error CS0103: The name `FindObjectOfType’ does not exist in the current context

my code seems to be ok, can anyone help me?

[ if(rb.position.y < -2f)
        {
            Debug.Log("TOT");
            FindObjectOfType<GameManager>().GameOver();
        }

]

Game over is a function that ends the the game and sits on the Game Object GameManager, that has a script called GameManager.

am i missing something completly obvious here?

  • Liked by
Reply
0 on December 23, 2017

Does your script derive from MonoBehaviour? if not simply change 

FindObjectOfType<GameManager>().GameOver();

to

Object.FindObjectOfType<GameManager>().GameOver();

  • Liked by
Reply
Cancel