Hello. After a condition happens, how can I deactivate a child object of the object that the script is attached to? To help explain that better its set up like this (I want to make the “Shoot” Game object stop for a few seconds and then start again).
Hierarchy
Player (Game Object) with the “Collide” script attached to it.
–Shoot (Game Object)
Thanks.
Take a look at Transform.Find().
Just as Jesse answered or…
gameObject.Find(“Shoot”).active=false;
However, I don’t think that is going to provide you with what you are trying to do. This will remove the object from the scene during that time. If you want to stop it you’ll need to script that somewhere. Stop it’s transform.position for a while and then restart it.
If you take a look at the FPS tutorial, there is some code in there which handles reloading. You can set a time in there which is very similar to what you are doing here so you can probably adapt that if you wanted.
I tried implementing that and it does not work, the object is still active?
function OnTriggerEnter (other : Collider) {
if (other.gameObject.CompareTag ("Enemy")) {
Stats.Life -=1;
gameObject.Find("Shoot").active=false;
}
Is “Shoot” the exact name of the GameObject?
Did you check in the editor during gameplay to see if that specific GameObject was indeed deactivated (unchecked and grayed out)?
Yeah, “Shoot” is the name and it’s box gets unchecked but it is still going (it has a script that spawns projectiles and they are still spawning), what’s going on? If I unchecked it’s box before I play the scene, the projectiles don’t spawn.
Can you post the part of the code where the projectiles get spawned?