- Home /
GameObject[] Issues
Im having an issue with the following script: var object1 : GameObject[];
function OnMouseDown()
{
object1.gameObject.SetActive (true);
}
And this is the issue im receiving: NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args) UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args, System.Type scriptBaseType)
Im assigning the objects correctly, am I not? Whats going on?
Answer by YoungDeveloper · Jun 23, 2015 at 12:22 AM
object1 is an array
If you want it to be treated as single gameobject, it should be
var object1 : GameObject;
if you want a primive collection, then you should access it by
int index = 0;
objects[ index ].gameObject.SetActive (true);
should I keep the variable as var obect1 : GameObject[]; ??? or just use the int
Im confused about how to implement it. If i do it like this: http://unity3d.com/learn/tutorials/modules/beginner/scripting/variables-and-functions Its just treated as a int, and i cannot choose the game objects to use?
YoungDeveloper told you exactly how to implement it. if object1 is an array of GameObjects, you access one of the array's element's (GameObjects, in this case) by passing it the index number. object1[indexOfGameObject].SetActive (true);
Your answer
Follow this Question
Related Questions
!IsActive && !GetRunInEditMode 5 Answers
SetActive is giving me a lot of issues 2 Answers
Simple GameObject Hide/Unhide with bool!!! 0 Answers