this is my script:
#pragma strict
var fouts : AudioClip;
private var hit: RaycastHit;
function Start () {
}
function Update () {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast (ray, hit , Mathf.Infinity))
{
if (hit.collider.tag == "goed")
{
Application.LoadLevel(Random.Range(2, 11));
highscore.score += 1;
}
if (hit.collider.tag == "fout")
{
audio.Play();
Application.LoadLevel("gameover");
}
}
}
}
now i want it to load a random level from 2 to 10 but number 4 how do you set this up?
This should work better.`
var LevelOptions : int[] = [2, 3, 5, 6, 7, 8, 9, 10];
Application.LoadLevel(LevelOptions[Random.Range(0,LevelOptions.length)]);
use this:
var LevelOptions : int[] = [2,3,5,6,7,8,9,10];
Application.LoadLevel(Random.Range(0, LevelOptions.length));
Zentiu
4
seems you need to make the script bigger with random range
just make a random range of 1 through 8 ( since you want 1 of those 8 in your array to be called)
then make like 8 if statements.
like:
randomNumber = Random.Range (1,8);
if(randomNumber == 1)
{
//do this.
}
if(randomNumber == 2)
{
//do that.
}
/ect.
better yet, make a switch statement.
Switch(randomNumber):
{
case (1):
{
//do this.
Break;
}
case (2):
{
//do that.
Break;
}
//ect.
hope this helps.