unity3d - Randomize game objects actions, so they won't happen at the same time -


i wrote script change states npcs. run function return either true or false. if true, npc change state.

all fine, except see more 1 npc acting @ same time, horrible. feels military squadron, synced.

i use random value check if function should return true or false...but expecting see different results each npc, since random value in place

class void npcstate() {      private system.random rnd = new system.random();     private string state;          void start()     {         state = "state1";         startcoroutine("runaction");     }      ienumerator runaction()     {         ...do stuff every n cycles         switch (state)         {               case "state1":                 ... go state 1                                 break;             case "state2":                 ... go state 2                 break;         }     }        void state1()     {         ... execute tasks         if (changeactiontype)         {              ...change different action type              state = state2;         }     }      void state2()     {         ... execute tasks         ... go previous task         state = state1;     }      private bool changeactiontype()     {         if (rnd.next(100) > 50)             return true;         else             return false;     } } 

i did simplify code show part state change; , happening @ same exact time multiple npc.

how can create enough variety in script, each npc may update @ random time? want avoid act synchro swimmers :)


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -