So Ive used GameObject.active = true for quite a long time, however I am trying to get to learn SetActive as its updated and preferred, however I have kindof an issue when I try to use it, here is the script
`var obj1 : GameObject;
function Start()
{
obj1 = GameObject.FindGameObjectsWithTag(“TheObj1”);
if (PlayerPrefs.GetInt("ObjOn")==1)
{
obj1.GameObject.SetActive (true);
}
else if (PlayerPrefs.GetInt("ObjOn")==0)
{
obj1.GameObject.SetActive (false);
}
}`
and the error is:
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)
ObjOnJV.Start () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/Camera/ObjOnJV.js:9)
c# insists on writing Gameobject like this: obj1.gameObject.SetActive (true) (lower case at the beginning). I don't know if US has the same limitation.
– HrungdakTo properly format your code use the 101 010 button. For more information on how to effectively use Unity Answers watch the Unity Answers tutorial https://www.youtube.com/watch?v=ezAPpViLs2Q and read the faq: http://answers.unity3d.com/page/faq.html.
– maccabbe