Random.Range not working.Am I doing this wrong?

Hello, I want my enemies to drop items upon death, so i did :

var ChanceRange = 5;

	if(EnemyHp < 10){
		if(Random.Range(1, ChanceRange) == 2){
		 Instantiate(Item1,transform.position,transform.rotation);
		 }
Destroy(gameObject);
}

The problem here is that when i use Random.Range(1, 5), it works fine, but when I use ChanceRange instead of 5, it doesn’t work (no items dropped if ==2 ; items ALWAYS dropped if ==1, which leads me to believe that it is ignoring the variable cimpletely) . I need to have it as a variable because I’m going to make items that change the percentage of item drop. Any help would be appreciated.

In my opinion, you’re better off setting the random to a variable. Makes debugging that much easier if you can see what the number is. Also, cast it as an int because if it’s a float, the chances of it being exactly 2 are very, very small.

var chanceRange:int; perhaps

Thanks for the replies. I tried making it an int, still didn’t work. Not sure why this is happening, it’s as if the variable is being ignored completely, I checked for spelling mistakes and stuff. It seems pretty illogical to me, I’ll look into this and if I figure something out I’ll post back.

Public variables take their value from the inspector, not your code.

Makes no difference; 5 is an int so the type is int.

–Eric