I am making a small riddle game and you are given a random riddle. When you solve the riddle, the riddle game object is destroyed. I made an array with all the riddles and the script randomly picks 1 riddle. The problem is that if(currentRiddle == null) doesn’t work and it moves to if(currentRiddle != null) which works and it causes an error. Is there any way to fix this?
public void PickRandomRiddle()
{
index = Random.Range(0, Riddles.Length);
currentRiddle = Riddles[index];
if (currentRiddle == null)
{
PickRandomRiddle();
}
else if(currentRiddle != null)
{
currentRiddle.SetActive(true);
print(currentRiddle.name);
}
}