Okay so as I have posted before I am making a pokemon game based on a tutorial as a learning experience. I managed to create a day and night system based on the time of the computer running the game, and ascribed a variable that determines if it insight or day.
I also have a script applied to the map that creates a list of wild pokemon that can be encountered that is be filled out in the inspector. Now the problem is I tried to use the day/night variable to make two different lists of wild pokemon you can encounter based on the time. I tired to call the is it night or day variable from another script but I am not sure it is working.
Here is the script.
{
[SerializeField] List<Pokemon> wildPokemonsDay;
[SerializeField] List<Pokemon> wildPokemonsNight;
public Pokemon GetRandomWildPokemon()
{
if (FindObjectOfType<TimeKeeper>().isNight)
{
var wildPokemon = wildPokemonsDay[Random.Range(0, wildPokemonsDay.Count)];
wildPokemon.Init();
return wildPokemon;
}
else
{
var wildPokemon = wildPokemonsNight[Random.Range(0, wildPokemonsNight.Count)];
wildPokemon.Init();
return wildPokemon;
}
}
}
So if I run the game with this only if (FindObjectOfType().isNight) is run. The else does not; I know this because I ran a debug.Log, and it never got triggered even when the game was day. I have two possibilities as to the cause. First, the (FindObjectOfType() does not work as intended, or The way the GetRandomWildPokemon() is written, it can not have two return results.
Is either of these conclusions right, or is it something else entirely?
Also, It won’t let me make the else statement an else if in the function.