- Home /
Cannot Instantiate Object
There are no errors on console but the script doesnt work right , it doesnt spawning object , here is the script ;
#pragma strict
public var haydutini : Rigidbody ;
private var inpos = new Array();
private var spawnpos : Vector3 ;
private var i : int ;
private var randbool : boolean = false ;
function Start () {
var spawnlair : Rigidbody;
randbool = true;
for(i=0 ; i<inpos.length ; i++)
{
spawnpos = inpos[i];
spawnlair = Instantiate(haydutini,spawnpos,Quaternion.identity);
}
}
function Update ()
{
if(randbool)
{
inpos[0] = Vector3(Random.Range(857.0f,1173.0f),81.3f,Random.Range(1077.0f,1500.0f));
inpos[1] = Vector3(Random.Range(960.0f,1240.0f),103.0f,Random.Range(2200.0f,2800.0f));
inpos[2] = Vector3(Random.Range(0.0f,220.0f),81.3f,Random.Range(2500.0f,4900.0f));
inpos[3] = Vector3(Random.Range(1470.0f,2136.0f),116.5f,Random.Range(1930.0f,1990.0f));
inpos[4] = Vector3(Random.Range(2680.0f,3200.0f),81.3f,Random.Range(1350.0f,1770.0f));
inpos[5] = Vector3(Random.Range(3600.0f,4000.0f),81.3f,Random.Range(3600.0f,4000.0f));
inpos[6] = Vector3(Random.Range(3600.0f,5000.0f),81.3f,Random.Range(0.0f,200.0f));
inpos[7] = Vector3(Random.Range(4850.0f,4990.0f),165.0f,Random.Range(1000.0f,2800.0f));
inpos[8] = Vector3(Random.Range(3350.0f,3750.0f),81.3f,Random.Range(300.0f,848.0f));
inpos[9] = Vector3(Random.Range(3830.0f,4027.0f),81.3f,Random.Range(2200.0f,2525.0f));
inpos[10] = Vector3(Random.Range(4600.0f,4990.0f),81.3f,Random.Range(3170.0f,3400.0f));
randbool = false;
}
}
haydutini is rigidbody. Try to use haydutini.gameObject in Instantinate method
inpos is simply empty in the Start function. Thus, inpos.length = 0, so you don't go into the for loop
Answer by Foulcloud · Aug 24, 2015 at 08:57 PM
Make sure any prefab you want to instantiate is in the "Resources" folder.
Your answer

Follow this Question
Related Questions
How would i use a 2D array for level generation 0 Answers
IndexOutOfRangeException: Array index is out of range when using an Array and instantiating 2 Answers
Array with game object: object reference not set to an instance of an object 1 Answer
How to Instantiate a Different Game Object After Getting to the End of an Array? 1 Answer