Get static var inside coroutine (C#)

Hey guys,

Ive got the following code in one script called “Script1”:

public static int testVar=0; 

And this code in my other script called “Script2”:

void Start()
	{
		StartCoroutine(doSomething());
	}

	IEnumerator doSomething(){
		if (Script1.testVar==1)
		{
            (...)                   
		}
	}

I get the error that Script1 would not exist in the current context. So am I right, that it is not possible to get a static var from another script inside a coroutine? How should I solve this problem?

You should read about script compilation order and groups. Scripts which are places in the first group are compiled first. That means they can’t access anything which is compiled in a later group since they aren’t compiled yet. The second group has access to everything in it’s own group and the group before. Since the first group is already compiled, the compiled assembly can be referenced when compiling the second group. this goes on like this up to the last group.

Group 1 and 3 are your actual game scripts. Group 2 and 4 are only for editor scripts.

I guess you have places some scripts either in the “plugins” folder or “Standard Assets” folder. That will cause them being compiled before the “normal” script which are outside of those folders.