- Home /
Timed event Question
I am not sure how to approach this - I have a day/time cycle and the 24 hours cycle is a variable - in my case, 30 minutes; That means night takes 15 minutes, day - 15 minutes. Now, I want to activate a rain gameobject at night but with a random value; say, it rains at night only but every other 2 or 3 "days".
Any ideas on how to/where to start with this? Thanks in advance!
Setup a day/night bool, when you change this value use random range to deter$$anonymous$$e weather or not it will rain this night or not.
Answer by Anxo · Nov 20, 2014 at 04:29 PM
Not that this code will work as it is WUCC but this is the logic I would use.
int rainFreeNights ;
int nightCount = 0;
bool itIsDayTime;
void SetRainFreeNights(){
rainFreeNights = Random.Range(0,3);
}
IEnumartor MakeItRain(){
while(itIsDayTime) yield return null;
if(nightCount == rainFreeNights){
SetRainFreeNights();
nightCount =0;
RainGameObject.SetActive(true);
}else{
nightCount++
}
while(!itIsDayTime) yield return null;
}
Answer by White-Chocolate-Development · Nov 25, 2015 at 12:19 PM
using UnityEngine; using System.Collections;
public class TimeOfDay : MonoBehaviour {
public float time = 0.5f;
void Update () {
this.transform.Rotate (Vector3.right * time * Time.smoothDeltaTime);
}
}
This is only for the day and night cycle. You can switch the speed by changing the float in the properties window.
For the rain you can create a var called days and make it a random setting the range to be from 2-3. Then for what ever number the var days is that is when it will rain.
Your answer
Follow this Question
Related Questions
How to impliment a 10 minute day clock, and tie it to a directional light rotation. 4 Answers
Unity2D Day and Night Cycle 0 Answers
Creating a script to randomize events. 1 Answer
I can't get my script to work I get an error. [Please Help!] 0 Answers
How do you access the "Auto Time" or "Network-Based Time" on Android? 1 Answer