Public variable not showing in Inspector(Solved)

I had a quite simple script that kept count of the number of enemies in my scene and when that reached zero it loaded the next scene. Now I have multiple scenes I needed to change the variable number in the inspector for each scene rather than have a new script each time.

But for some reason the changing the variable to a public one has not let it show up in the inspector?

using UnityEngine;
using System.Collections;

public class LevelCleared : MonoBehaviour
{

	public static int enemyNumbers = 10;


	void Awake()
	{
		//enemyNumbers = 21;
	}
	
	void Update()
	{
		if(enemyNumbers <= 0)
		{
			var i = Application.loadedLevel;
			AutoFade.LoadLevel(i+1 ,2,1,Color.black);
			//Parameter 1 - LevelName or LevelIndex
			//Parameter 2 - FadeOutTime - time in seconds until the level actually starts loading
			//Parameter 3 - FadeInTime - time in seconds until the fade-in process is completed.
			//Parameter 4 - FadeColor - this is the color the screen fades to.
		}
	}
}

The variable was originally a static in, now public static. The commented out line in the awake function is just a left over from when there was a single scene.

I’m getting no compiler errors and the script still does what I need depending on what number I set the int variable to. It just doesn’t show in the inspector so I have to manually change the script.

Any ideas

???

edit…

Script is attached to a sceneManager object in my scene and accessed from another script using -

LevelCleared.enemyNumbers -= 1;

???

ok problem solved (although I’ll admit I don’t understand why…lol)

using UnityEngine;
using System.Collections;

public class LevelCleared : MonoBehaviour
{

	public int killCount = 10;
	public static int enemyNumbers;
	

	void Awake()
	{
		enemyNumbers  = killCount;
	}


	void Update()
	{
		if(enemyNumbers <= 0)
		{
			var i = Application.loadedLevel;
			AutoFade.LoadLevel(i+1 ,2,1,Color.black);
			//Parameter 1 - LevelName or LevelIndex
			//Parameter 2 - FadeOutTime - time in seconds until the level actually starts loading
			//Parameter 3 - FadeInTime - time in seconds until the fade-in process is completed.
			//Parameter 4 - FadeColor - this is the color the screen fades to.
		}
	}
}

Changing the enemyNumbers to a public static in (in conjunction with the killCount variable) works fine. I get to edit the value in the inspector and still access the script from other scripts.

Seems like a waste of time to me, I’m still able to influence a static variable from the inspector, just takes another few lines of code to do it. I mean… why not just make it possible to have a public static int in the first place.

Anyway, all sorted. Thanks for the help guys

:slight_smile: