The question is answered, right answer was accepted
SetActive() trouble
Hi comm unity ))) I've got some problem with UI Panel. On Panel I got code: using UnityEngine; using UnityEngine.UI; using System.Collections;
public class Activate : MonoBehaviour {
void Awake () {
gameObject.SetActive(false);
}
}
It's disable my PopUp panel on start.
On Button I got code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class PopUp : MonoBehaviour {
GameObject getPopUp;
public void clickedPopUp()
{
getPopUp = GameObject.Find("PopUp");
getPopUp.SetActive(true);
}
}
So, Panel disabling perfectly, but when I'm trying to SetActive(true), it's gives me ERROR : NullReferenceExeption.
I'll be glad if someone will tell my how to fix it)
Answer by Losteone · Apr 27, 2016 at 07:24 PM
So, I kinnda find an option to solve this)
I've changed Awake on Start in 1st code, then create Awake in 2nd code and transfer getPopUp = GameObject.Find("PopUp") to Awake, so it can find gameObject before it goes Inactive )))
Follow this Question
Related Questions
Basic Code Problem 1 Answer
Double Input.GetButton problem. 1 Answer
gameObject.SetActive (false); Not working 0 Answers
gameObject.SetActive (false); Not working 0 Answers
WaitForSeconds doesn't work when seconds is greater than 2 0 Answers