Different random number output at the same time (Unity C#) -



Different random number output at the same time (Unity C#) -

i'm making first game using using unity3d written in c#. i'm doing part player can different attack chance. eg. if it's critical chance set 20%, it'll create critical damage.

my problem it's random number generator making same output eg. when makes critical damage, create stun harm when requirements met. want is, there's different random value critical, stun, etc. have read can utilize random.next, it's not working in unity3d though it's both c#. i've done

private float _criticalchance; private float _stunchance; // utilize initialization void start() { _criticalchance = random.range (0f, 1f); _stunchance = random.range (0f, 1f); }

then see in it's debug.log outputs same value.

this i've , want want. i'm getting , error when seek initialise variable method i've do.

private float chance; private int choice; void start() { chance = random.range(0f, 1f); selection = random.range(0, 2); } void update() { chance = random.range(0f, 1f); selection = random.range(0, 2); } public void gethit(int damage) { if(chance <= fighter.attribute.criticalchance && chance <= fighter.attribute.stunchance) { if(choice == 0) { attribute.maxhealth -= harm + (int)(damage * fighter.attribute.criticaldamage); } else { getstun(fighter.attribute.stuntime); attribute.maxhealth -= (int)damage; fighter.attribute.resetstun(); stunned = true; } } }

c# random unity3d

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -