How to Ramdom.Range but if an action is complete???

function OnCollisionEnter (col : Collision)
{
if(col.gameObject.tag == “Bullet”)
isdodge = true;
escolher = Random.Range (1,6);

Debug.Log (escolher);
if (escolher == 1 )
vel = 120;
estranho.transform.Translate (0,0,vel * Time.deltaTime );

if (escolher == 2 )
vel = 125;
estranho.transform.Translate (0,0,vel * Time.deltaTime );

if (escolher == 3 )
vel = 120;
estranho.transform.Translate (0,0,vel * Time.deltaTime * -1);

if (escolher == 4 )
vel = 120;
estranho.transform.Translate (0,0,vel * Time.deltaTime * -1);

if (escolher == 6)
isdodge = false;
}
The problem is that the ramdom.range in each secods choose another number,and don’t allow to make the action to translate until the end,how can i solve this issue
i’m aprreciated!

hi , thought i would put a couple of thoughts down to try and help :slight_smile:

your random.range if your looking to include all the integer numbers 1 to 6, then it should be

Random.Range (1,7);

as the max of this is exclusive and is never reached.

might be worth trying this in a case statement.

if your trying to get this called only once in a given time frame, then might be worth wrapping this up in an IF statement with a bool flag that allows the dodge action to be carried out.

1 Like

Appreciated!

Nope. If you want intergers, the last number is inclusive.

Random.Range (1,6);

you linked to the docs page, but did you even read it?

public static int Range(int min, int max);
Description
Returns a random integer number between min [inclusive] and max [exclusive] (Read Only).

If max equals min, min will be returned. The returned value will never be max unless min equals max

Well crap sorry bout that