J
J
Jesus_newrba2018-11-25 11:25:49
C++ / C#
Jesus_newrba, 2018-11-25 11:25:49

How to make a random event generator in unity3d?

There is an event (Attack of enemies, rain, cold, attack of wild animals, etc.), how to trigger one of the random events on a random day

spoiler
void Timer () {
    time+=Time.deltaTime;
    if (time > 480) {
      day += 1;
      time = 0;
    }

  }

How to implement all this >_<???

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Pogrebnyak, 2018-11-25
@Jesus_newrba

If all events are of the same type, and, for example, are stored in the same array, then something like this can be done:
If they are of different types, then you can do this:

switch (Random.Range(0, N))
{
case 0:
      EventEnemiesAttack();
      break;
case 1:
      EventWeatherRain();
      break;
case 2:
      EventWildAnimalsAttack();
      break;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question