- Home /
How do i deactivate a GameObject from js
I have a simple script I want to deactivate a gameObject that it is attached to. This is what I have but it does not work
#pragma strict
public var SubtractOne : GameObject;
function Start () {
game.noOfHits = -1;
SubtractOne.SetActive(false);
}
function Update () {
}
Thanks Brandon
I tried
gameObject.SetActive(false);
But still no luck it still shows active in the inscpector
Never $$anonymous$$d figured it out I actually wanted that under function Update
thanks
Answer by robertbu · Dec 10, 2013 at 08:07 PM
Doesn't work how? Not do anything? Causes and error? Is SubtractOne initialized in the Inspector? Are there any other scripts manipulating the game object that is initialized into SubtractOne?
If you just want to deactivate the game object this script is attached to, you can do:
gameObject.SetActive(false);
Converted to Answer. If you're unhappy with it, slap me a message and comment yourself back. But I think it's a good an answer as any :)
I created a empty gameobject then attached this script. When the game starts the gameobject is deactivated then get activated in the game all I want it to do is pass the var, Which it does but it never deactivates the gameobject that it is attached to.
Thanks Brandon
Your answer

Follow this Question
Related Questions
static var for one object. 2 Answers
Get game component type? 1 Answer
error with maxbackwardsSpeed 1 Answer
Get Vector3 position of player? 0 Answers