- Home /
Objects not becoming active with script
My problem: I want to enable a game object after a period of time. I figured since the same script works opposite with SetActive(false) it would work. It did not. My code has no errors - its just not working. Help?
using UnityEngine;
using System.Collections;
public class SpawnDelay : MonoBehaviour {
public float delayTime = 5.0f;
IEnumerator Start ()
{
yield return new WaitForSeconds (delayTime);
this.gameObject.SetActive (true);
}
}
Thank you in advance!
Answer by oasisunknown · Jun 07, 2014 at 03:13 AM
I think that your problem is that the gameObject is already inactive. that should mean everything on that object is inactive scripts included.
put in a
Debug.Log ("Test to see if this script is active");
just before you try to turn the gameObject back to true.
if the debug does not show up then I am right and the whole script is off and you will probably have to use another script that is active to tell this one to wake up through a reference.
This is the best reference that I know of off hand that talks about enabling and disabling gameobjects for pooling purposes. I have not yet watch the whole thing but I just skimmed through it to make sure he was talking about.
give it a quick look and see if it helps
http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-pooling
the coding you would be interested in really starts around $$anonymous$$ute 10.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Physics not working with Character Controller 1 Answer
Distribute terrain in zones 3 Answers
script only working on first run 1 Answer
Why is this code glitching? 2 Answers