Make repeatRate a random number...
Hello, I'm brand new and don't have much experience at all... I would like the following spawn obstacle to repeat at random intervals.
In my head I would set repeatRate to a random range or such but that isn't working.
So, firstly, is this the best place to get my question answered? Should I be looking elsewhere for further reading as this is so basic? And how do I get this randomised!
Cheers! Here is my Spawn script:
public class SpawnManager : MonoBehaviour { public GameObject obstaclePrefab; private Vector3 spawnPos = new Vector3(25, 0, 0); private float startDelay = 2; private float repeatRate = 2; private PlayerController PlayerControllerScript;
// Start is called before the first frame update
void Start()
{
PlayerControllerScript = GameObject.Find("Player").GetComponent<PlayerController>();
InvokeRepeating("SpawnObstacle", startDelay, repeatRate);
}
// Update is called once per frame
void Update()
{
}
void SpawnObstacle ()
{
if(PlayerControllerScript.gameOver == false)
{ Instantiate(obstaclePrefab, spawnPos, obstaclePrefab.transform.rotation);
}
}
}
Your answer
Follow this Question
Related Questions
How can you do borderlands style random weapons and stat generation? 2 Answers
Choose something randomly based on its grouping 0 Answers
What is the difference between System.Random and UnityEngine.Random? 3 Answers
How to pick two random gameobjects in an array at the same time? 1 Answer
Spawning objects at runtime in vertical-scroller game 0 Answers