What is this series about
In this series I will be discussing the process of how I made my first mobile application, Dr. Dino, giving you tips, tricks, and tutorials on how you can get started with game development.
If you want to check out the first game I ever created, click the button below:
In this post, we will discuss how to make infinite obstacles for your game.
making infinite obstacles
The C# Script
The pictures below illustrate a sample C# script that could work to make an infinite amount of obstacles for your game. The main components of this script are the maxTime and Instantiate() function. The maxTime is the value that sets the time between when a new obstacle is spawned.
In the case below, the max Time is set to 0.6f initially and if then decreased by a set increment after timer2 exceeds the decrease value.
The Instantiate function is important because it basically duplicates our obstacle GameObject and from there we can use the transform.position function to change the position of the duplicated obstacle.
Implementing the Script
After you make the script, you have to implement the code into your game. To do so you first need to make a new empty game object. For simplicity, name the empty game object “Obstacle Spawner”.
Next, you should drag the C# script you created into “Obstacle Spawner”. When you complete this task, you should see that you need to input a value for timer, timer2, decrease, increment, range, and obstacle.
Finally, you should play around with the each of the values until they make sense within the context of your game and allow for a fun but challenging play through.