Hey guys,
I’m trying to make a system where if u press the right arrow it switches to an item that’s next in line, and than it fills that next item slot with an Instantiate command.
So basically two game objects “next” and “current”, and when you press right current is emptied, next goes into current and next is randomly instantiated.
I’m very new to Unity so im struggling to get this to work.
#pragma strict
var options : GameObject[];
var next : GameObject;
var current : GameObject;
//var totalScore : float;
var randNum : int;
var pos1 : GameObject;
var pos2 : GameObject;
function Start () {
current = Instantiate(options[RandomNum()], pos1.transform.position, pos1.transform.rotation);
next = Instantiate(options[RandomNum()], pos2.transform.position, pos2.transform.rotation);
}
function Update () {
if (Input.GetKeyDown(KeyCode.RightArrow)) {
next = current;
next = Instantiate(options[RandomNum()], pos2.transform.position, pos2.transform.rotation);
} else if (Input.GetKeyDown(KeyCode.Return)) {
//+= totalScore;
}
}
function RandomNum () {
randNum = Random.Range(0, options.length);
return randNum;
}