I'm creating a script to randomly spawn a ''zone'' into the map in which the player has to stand in to generate points. I've got most of the point system and zone system in place and am able to kill the zone (and destroy the object) when max points per zone is met.
I now want to pick a random zone when ever zoneAlive == false. I figure I can use a float variable to select a Zone ID and then use Random.range to pick a random ID from X to X. I'm generating a CS0029 error in doing so.
zoneGameHandler.cs(47,25): error CS0029: Cannot implicitly convert type `float' to `UnityEngine.Random'
Here is my line of code:
random = Random.Range(0f, 5f);
print (random);
I know this is probably a very rookie mistake so it shouldn't cause anyone a headache seeing this newbie question pop up.
You haven't shown where you've declared random
, but I suspect you've used:
Random random;
whereas you actually want the type of random
to be float
:
float random;
...
random = Random.Range(0f, 5f);
Alternatively, declare the variable where you're initializing it:
float random = Random.Range(0f, 5f);
If you're writing this as a script, use var random : float
instead of var random : Random
.
See more on this question at Stackoverflow