# Random.Range statement question

 0 I'm trying to select a random number from 1 - 4. Here's my script - what's wrong with it? It only gives numbers from 1-3. ``````var ground : GameObject; var numberOfBuildings : int = 20; var numberOfRows : int = 5; var building1 : GameObject; var building2 : GameObject; var building3 : GameObject; var building4 : GameObject; var position = Vector3 (10,0,10); var buildingType = 4; var zchange = 10; var nothing : GameObject; function Start (){ var newObj = Instantiate (ground, Vector3(0,-0.1,0), transform.rotation); newObj.transform.localScale.z = numberOfBuildings*20; newObj.transform.localScale.x = numberOfRows*40; } function Update () { if (numberOfBuildings > 0) { buildingType = Random.Range (1,4); print (buildingType); switch (buildingType) { case (1) : Instantiate (building1, position, transform.rotation); position += Vector3 (0,0,zchange); numberOfBuildings--; break; case (2) : Instantiate (building2, position, transform.rotation); position += Vector3 (0,0,zchange); numberOfBuildings--; break; case (3) : Instantiate (building3, position, transform.rotation); position += Vector3 (0,0,zchange); numberOfBuildings--; break; case (4) : Instantiate (building4, position, transform.rotation); position += Vector3 (0,0,zchange); numberOfBuildings--; break; } } } `````` Thanks! more ▼ asked Apr 24 '11 at 08:23 PM Muzz 1 548 ● 52 ● 59 ● 71 When you get this finished I'd like to see it Muzz. It looks interesting. Apr 25 '11 at 01:03 AM burgunfaust add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 static function Range (min : int, max : int) : int 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. Make it: `````` Random.Range(1,5); `````` http://unity3d.com/support/documentation/ScriptReference/Random.Range.html Exclusive means it doesn't read that one... Think of in Java like doing a substring function... If you know that... But yea, this'll work =). more ▼ answered Apr 24 '11 at 08:28 PM Justin Warner 6.3k ● 19 ● 27 ● 65 That's just so messed up... Apr 24 '11 at 08:42 PM Muzz 1 Yea... I think it's funny that if you use floats instead of an int, it is inclusive inclusive... So then the second number IS included... Haha. Apr 24 '11 at 08:43 PM Justin Warner Also, when I used (1,3), it gave me those 3 values. I will never get scripting. Apr 24 '11 at 08:43 PM Muzz 1 Hmm, that's very strange... It might be a small glitch, never know... Apr 24 '11 at 09:28 PM Justin Warner add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x5275
x3570
x599
x111

asked: Apr 24 '11 at 08:23 PM

Seen: 1623 times

Last Updated: Apr 24 '11 at 08:23 PM