How do you add an integer to a random.range?

Working on a lock picking scenario and I am having troubles on figuring out how to add int to a random.range. The int is the lock picking skill currently possessed by the player, and the random.range is the rolled numeral needed to pick the lock. I also have a set numeral that defines the lock strength which is 10. The int needs to be added to the random.range to be >= the lock strength to pick it.

This is for my lock:

var DoorOpen : boolean = false;
var randomNumber : int = 0;
var LockStrength : int = 10;

function Start () {

}

function Update () {



}

function OnMouseDown (){
	randomNumber = Random.Range(1,8);
	print(randomNumber);

		
		
			if(DoorOpen == true){
			animation.Play("door1anim");
			}

			

}

This is for my character:

var wire : Door1;
var PickSkill = 5;

function Start () {

}

function Update () {

}

I formatted your code for you, but please, in the future, use the little button marked with the '101010' to paste code. Thanks!

2 Answers

2

You mean something like this?

function OnMouseDown() {
     var randomNumber = Random.Range(1,8)+5; // 5 is the PickSkill
     if (randomNumber >= LockStrength) {
          animation.Play("door1anim");
     }
}

Now how you reference the variable PickSkill, rather than hardcoding the number 5 is a topic for a whole new question.

some_int = Mathf.RoundToInt(UnityEngine.Random.Range(Af, Bf));

A = first number in the range

B = last number in the range