SetActive dosen't work
Hey, I'm trying to make an Guess the movie app. But I have an problem whit making it so when the person answers correctly on one of the movies, which is it's own scene. It jumps out to a scene called "Level 1" and on this page I need to make it so the player sees that he answered correctly. I thought to make an image appear over the button(To the movie), but I don't know how I'm gone make that work. I have tried to make it so when they answer correctly 1 point gets added to a score counter And on scene "Level 1" it reads the score and if (score = 1) then gameObject.SetActive(this.gameObject) but nothing happends. Maybe I can use PlayerPrefs and GameObject.activeSelf to save the state of the image? :/ I will really appreciate any help, so thanks in advance :)
I have used this:
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class ImageStatusCheck : $$anonymous$$onoBehaviour {
void Update () {
GameObject ff = GameObject.Find ("ImageStatus");
ImageStatus df = ff.GetComponent<ImageStatus> ();
if (df.state == 1) {
gameObject.SetActive(true);
}
}
}
@$$anonymous$$ristianGrytdal GameObject.Find doesn't work on inactive gameobjects. Nothing will find an inactive gameobject, thus you must first save a reference to the gameobject before making it inactive in the first place. This can be done in the editor by using a public GameObject myObject and drag-and-drop it or you can find it in the Start()-function and then use SetActive(false).