Instantiate random object from Array

Hello Guys, I’m 15 years old applicaton developer from turkey. So I have a problem about a script.

#pragma strict

//---------------------------------------

var waitFor : int;

var waitMin : int;

var waitMax : int;

//-----------------------

var possibleLeft = new Array(RCloud1, RCloud2, RCloud3, RCloud4);

var possible;

//-----------------------

var RCloud1 : GameObject;
var RCloud2 : GameObject;
var RCloud3 : GameObject;
var RCloud4 : GameObject;

//-----------------------

function Awake (){

possibleLeft = Random.Range(0, possibleLeft.length -1);

}

function Start () {

cloudScript ();

}

function cloudScript () {



waitFor = Random.Range(waitMin, waitMax);

Instantiate (possibleLeft, gameObject.transform.position, Quaternion.Euler(0, 180, 0));

yield WaitForSeconds(waitFor);



}

There’s my code. When i save it Debug Log gave me theese errors.

#1 = “Cannot convert int to Array” (28,28)
#2 = “No appropriate version of ‘UnityEngine.Object.Instantiate’ for the argument list ‘(Array, UnityEngine.Vector3, UnityEngine.Quaternion)’ was found.” (44,13)

What shall i do ? Please help me ! I’m stuck on this part. I want to create random clouds that will move around from one spawner. Thanks for reply.

  1. You are trying to assign int random value to array object. Maybe you meant:
    possible = possibleLeft[Random.Range(0, possibleLeft.length -1)];
  1. In your awake function, you are trying to assign an integer to an array value.
  2. You’re trying to instantiate an array instead of a gamoObject.

In both of these instances, change ‘possibleLeft’ to ‘possible’

Relevant code:

//1.
function Awake (){
possible = possibleLeft[Random.Range(0, possibleLeft.length-1)];
}

//2.
Instantiate (possible, gameObject.transform.position, Quaternion.Euler(0, 180, 0));