- Home /
Error when debuging array elements name
I have an array that I fill with gameObjects. When I try to debug the name of one of the array Items it brings up an error. (gameObject is not a member of object)
Here is the script
playerInv = new Array();
function OnCollisionStay(collided : Collision){
if(collided.tag == weapon){
playerInv.Add(collided.gameObject);
Debug.Log(playerInv[1].gameObject.name);
}
}
For one, you're missing a closing parenthisis on line 6.
Debug.Log(playerInv[1].gameObject.name);
Fix that first, then tell us what errors if any, and what line the error is on.
Opps, I fixed it, but that is still not the problem
I am a c# guy and don't know js well at all. In c# I know in order to use Add, you need to have either a List or an ArrayList ins$$anonymous$$d of an array...
Answer by Eric5h5 · Jul 07, 2013 at 02:15 AM
Don't use the Array class; it's slow and untyped (and being untyped is what's causing this particular problem). Use a generic List instead.
I used genearic list and debugged the gameObject object, not the anem
Your answer
Follow this Question
Related Questions
have array target person of most priority/stick with top prior 0 Answers
getting rid of empty elements in array 2 Answers
Array error - Index is less than 0... 3 Answers
IndexOutOfRangeExeption - Array index is out of range 2 Answers
Array variable assigned to instantiated object changes in all instantiated objects? 1 Answer