Quantcast
Channel: Latest Questions by SatisfactorySam
Viewing all articles
Browse latest Browse all 42

Creating a script to randomize events.

$
0
0
I've just started my very basic game. The player must complete a task within a certain amount of days. Once your turn is up, the day increases. Here is the script. using UnityEngine; using System.Collections; public class GameManager : MonoBehaviour { //Scripts public GameEvent GameEvent; //Declaring Variables public int CurrentDay = 1; public int MaximumDays = 10; void Update () { while(CurrentDay < MaximumDays + 1) { GameEvent.Day(); CurrentDay++; } } } You'll notice that I have imported a script called `GameEvent`. I call a function named "`Day`", which actually does nothing. It's blank. Then, the day increases and it goes through that loop until it hits the `MaximumDays`. Each day I just want something to happen. Let's say for now that some GUI will pop up with some information about that day. What if each day I wanted to randomize an event. Or in other words, make the GUI say something different based on a random number. At my level, I would probably make a random number, then create an insanely long if, if else, and else function depending on the number. Like this. if (RandomNumber == 1) { //Make the GUI say this. } else if (RandomNumber == 2) { //Make the GUI say something else. } else if (RandomNumber == 3) { //Make the GUI say something different. } //... There must be a much sexier way of doing this. Well, obviously. I just need some help. :)

Viewing all articles
Browse latest Browse all 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>