- Home /
GameObject SetActive not working
I don't know why it didn't work :/
using UnityEngine; using System.Collections;
public class ExampleCode : MonoBehaviour {
void Start()
{
gameObject.SetActive(false);
}
// Update is called once per frame
void Update () {
}
}
When I start the game, the gameObject is still visible :/ Can you help me? :D
Actually, your code should work and make the GameObject inactive. $$anonymous$$ake sure your script is enabled (check box to the left of the script). Also, are you sure there is no other script activating the GameObject somewhere else?
if this is the real code i think the variable of the gameobject is wrong but nothing else i see is wrong
Answer by UnrealSoftware · Dec 06, 2015 at 05:17 PM
What do you actually want to do? Do you want to enable or disable the game object? In case you want to enable it it should be
gameObject.SetActive(true);
instead of
gameObject.SetActive(false);
If it still doesn't work as intended: Make sure that the script is assigned to the right game object and also make sure that there is no other script which enables or disables the game object.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Rotation to certain degrees while holding a button? C# 1 Answer