Hi, I have a script with an enum called Weathertype. it has 3 states: sunny, rainy, snowy. For every state I have a script: Weather_sunny, Weather_snowy, Weather_rainy who all inherit from Weather_base.
I got a property of Weathertype which you can set with an enumpopup from a editorscript.
Now, when I change the state in the inspector, for example sunny, it enables the script Weather_sunny. When I change it to snowy after that, it enables Weather_snowy, but doesn’t disable weather_sunny.
How can I make it so that if I change the state, the script connected to the previous state gets disabled?
here’s the script with the enum:
public enum WeatherState
{
Sunny,
Rainy,
Snowy
}
[SerializeField]
private WeatherState m_eState;
public WeatherState State { get{return m_eState;} set{SetState(value);}}
public void SetState(WeatherState eState)
{
m_eState = eState;
changeState();
}
private void changeState()
{
switch(State)
{
case WeatherState.Sunny:
GetComponent<Weather_Sunny>().enabled = true;
break;
case WeatherState.Rainy:
GetComponent<Weather_Rainy>().enabled = true;
break;
case WeatherState.Snowy:
GetComponent<Weather_Snowy>().enabled = true;
break;
}
}