I am having difficulties creating a GameObject class, basically what I want is for unity to stop throwing errors when the powerUpPrefabs array is empty and ideally print out a debug.log saying that the array is empty.
private GameObject RandomPowerUp()
{
if (powerUpPrefabs.Length != 0)
{
return powerUpPrefabs[Random.Range(0, powerUpPrefabs.Length)];
}
else
{
//what do I type here so it doesn't throw an error?
}
}
What I am struggling with is figuring out what to type in the else statement, because it requires a GameObject to be return which neither the debug.log nor null is.
It depends on your code I would think NULL just check for that before you go instantiating something… or check that you have something in this array before calling this function and you could use if(powerUpPrefabs.Length > 1){//code}else return powerUpPrefabs[0];