- Home /
Instantiate randomly from array
Hello,
I try to make a game where an object appears one 1 of the 9 available places. But it sems that it doesn't work. Any help?
This is my code:
#pragma strict
var amplifier : float;
var Pos : GameObject[];
var popupObject : GameObject;
function Start () {
}
function Update () {
var instPos = Random.Range(0,(Pos.length - 1));
Instantiate(popupObject, instPos, transform.rotation);
}
Answer by YoungDeveloper · Oct 05, 2013 at 06:35 PM
You know what you forgot :)
Instantiate(popupObject, Pos[instPos], transform.rotation);
It gives me this error:
Assets/PopUp.js(12,20): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.GameObject, UnityEngine.GameObject, UnityEngine.Quaternion)' was found.
oh right !
Instantiate(popupObject, Pos[instPos].transform.position, transform.rotation);
Then post the new error, because that won't give you the same error as before.
Your answer
Follow this Question
Related Questions
How to set to game objects's position from 2 different game objects arrays equal to each other? 0 Answers
problem moving a prefab object in script (c#) 0 Answers
How to randomly pick a gameobject except for one gameobject in an array ? 1 Answer