- Home /
This question was
closed Apr 18, 2013 at 08:08 PM by
Graham-Dunnett for the following reason:
Problem is not reproducible or outdated
Array is out of range?
That kind of error comes up when I try to acces function Activation from other script. My script is as follows:
private var mysteryBox : GameObject[] = null;
var numbersToCreate : int = 0;
function Start ()
{
mysteryBox = new GameObject [numbersToCreate];
InstantiateMysteryBox();
}
function Activation()
{
for(var i : int = 0; i < numbersToCreate; i++)
{
if(mysteryBox[i].active == false)
{
mysteryBox[i].SetActiveRecursively(true);
mysteryBox[i].GetComponent(scriptMysteryBox).Activate();
return;
}
}
}
function InstantiateMysteryBox()
{
for(var i : int = 0; i < numbersToCreate; i++)
{
mysteryBox[i] = Instantiate(Resources.Load("Prefabs/prefabMysteryBox"));
mysteryBox[i].SetActiveRecursively(false);
}
}
Comment
Check that numbersToCreate is less than the array size and greater than -1. You need to check if GetComponent actually returned something before you call a function on it.
Before posting code, please tag it correctly and show some decency and format it for others to read.
I also really wish that I was allowed to post answers.
Follow this Question
Related Questions
Pooling object performs the same or worse than instantiate/destroy? 1 Answer
Index out of range exception - C# - Can't find the problem 1 Answer
Resource Being Deactivated 0 Answers
Array out of Range 1 Answer
How to control pooledObject? 1 Answer