If loop doesnt work in OnNetworkLoadLevel()

I am trying to load a prefab based on a variable, but unity wont do it.

If I take the if loop from around the code it works perfectly.
The thing is i did this in a previous project, and it worked great.

here is my code. I check and test is equal to 2.

OnNetworkLoadlevel()
{
   if(test == 2)
   {
     Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
   }



}

The only thing I can think of is that test is public and you have modified it in the editor, which overrides the value.

I changed the code to, and it works.
What could be causing this? test is an int.
This is very frustrating…

OnNetworkLoadlevel()
{
   if(test <= 2)
   {
     Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
   }



}

Like i said, if this is a MonoBehavior, check in the editor on the object you have it attached to. The editor value overrides the value you put in code.

I do not understand what you are saying here.
Can you explain?

Is “test” a public variable (and therefore exposed in the inspector of the Unity editor)?

Yes it is a public variable expose in unity editor.

He was saying that maybe you changed the value of it to something other than 2, in the editor. Because the value in the editor will always override the value in the script.

Could you post the whole script?

That is the whole script. The code works if i us >= .
Test is 2 in the editor.

var test : int = 2;


OnNetworkLoadlevel() 
{
   if(test == 2)
   {
     Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
   }



}

In what script is OnNetworkLoadlevel() called, and can you post that code?

That is the script. I copied the code and paste it.

I created a local variable and set it to zero. It seems that even though the editor says test is 2 it is actual zero.
It now spawn with the code below.

var test : int = 2;


OnNetworkLoadlevel() 
{
 var oner : int = 0;
   if(test == oner)
   {
     Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
   }



}

What’s probably happening is that, since test is a public variable, the value of test in the Unity Inspector (Not in the code) is set to 0. When you go to your Unity project, and click on the game object that has the script attached to it, you should see the value of the test variable in the Inspector. The value there is probably set to zero, which overrides the value you have in code.