- Home /
.SetActive(); not working in one method but is working in Start()
Basically im trying to enable a game over screen but the setactvie isn't working in the GameOver() method, i then tried using setactive in the start function and it works, ive also tried setting it to false instead of true and having it start on to test it and that didn't work either
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class gameOver : MonoBehaviour
{
private void Start()
{
//this was working when it wasn't a comment and the object was active before play
// gameObject.SetActive(false);
}
//is called without any paramaters
public void GameOver()
{
//this is printing to the console, confirming the method is running
print("gameOver");
//ive also set this to false and had it start as active to test and that didnt work either
gameObject.SetActive(true);
}
}
Answer by rh_galaxy · Mar 26 at 01:01 PM
I think it has to do with either a parent is inactive or the behavior of Start() or SetActive(). You must show more code to get help. Also read
https://docs.unity3d.com/ScriptReference/GameObject.SetActive.html https://docs.unity3d.com/ScriptReference/MonoBehaviour.Start.html
Answer by Serkan90 · Mar 26 at 08:53 PM
Its because the gameobject isn't active so the code won't work, you should create a parent object and have the script on that and that can control the child gameobject
Your answer
