Gamemanager does not exist in context? help me please

i dont know what to do i am new to coding and i am confused why
it says this
Assets/TimeDestroyer.cs(15,7): error CS0103: The name `GameManager’ does not exist in the current context
please help me. Thank you :smile:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

publicclassTimeDestroyer:MonoBehaviour
{

voidStart()
{
Invoke(“DestroyObject”,LifeTime);
}

voidDestroyObject()
{
if(GameManager.Instance.GameState !=GameState.Dead)
Destroy(gameObject);
}

publicfloatLifeTime=10f;
}

Do you have a script called GameManager?

Needs to match the spelling and caps.

how do i create that?

If you don’t have this script…or know how to make a new script, you’re going to have to learn how to do that.
Is this a copied script from somewhere?

yes it is

Ah…unfortunately, if you’re just copying scripts, you’ll have to get their GameManager script also and anything else that might be required. Otherwise, you’re going to have to learn what the original scripts do and learn to write your own using them as a reference.

We can’t really help you because you’re not asking for help on a script you wrote and trying to figure it out why it doesn’t work, but a script from someone else that relies on another script they probably wrote.

Either get with the programmer who made the script or add the GameManager script they wrote to your project.

When you post code snippets in this forum you should use the “insert code” option so the
code will be formatted and easier to read. like this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

publicclassTimeDestroyer:MonoBehaviour
{

voidStart()
{
Invoke("DestroyObject",LifeTime);
}

voidDestroyObject()
{
if(GameManager.Instance.GameState !=GameState.Dead)
Destroy(gameObject);
}

publicfloatLifeTime=10f;
}

On line 15, there is a conditional that checks the instance of a GameManager script to
see if the game is not dead before destroying the object. But as Brathnann mentioned
that script probably doesn’t exist in your project assets folder. You can make this script
work by commenting out that line like this:

// if(GameManager.Instance.GameState !=GameState.Dead)

but, it will only remove the check to ensure that the game state is not dead.
So, it’s a hack and it would be best if you include the GameManger script
in your project.