- Home /
Whats Wrong?
Hi, I'm trying to make an Array of game objects at Start found around an enemy using Physics.OverlapSphere, i thought this script I've done would do it, but says on the second find -
NullReferenceException: Object reference not set to an instance of an object
If I remark out
concreteBarriers[i] = current.gameObject;
it prints out all the names and numbers up to the 16 it finds, can someone point me in the right direction please.
function Start()
{
hide();
}
function hide()
{
var colliders : Collider[] = Physics.OverlapSphere (transform.position, lookForCoverRange);
var cover : GameObject[];
for (var current : Collider in colliders)
{
print(current.name + " Number " + i);
cover[i] = current.gameObject;
i++;
}
}
You need to give a bit more information. If you double click on the error message in Unity, what line in $$anonymous$$ono is highlighted? Where is concreteBarriers[i] declared and initialized?
Sorry, I'll take that on board for next time, sure there will be lots of next times ..
Answer by Doireth · Jan 31, 2013 at 03:17 PM
the "cover" array has not been initialised. Try
var cover : GameObject[] = new GameObject[colliders.Length];
Your answer
Follow this Question
Related Questions
Instantiate problem with multiple objects from an array 0 Answers
Confused using Arrays 1 Answer
CompareTag and OverlapSphere 1 Answer
how do I scroll thru a array 2 Answers