Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to make game object active with script

Discussion in 'Scripting' started by justadeveloper, Apr 5, 2015.

  1. justadeveloper

    justadeveloper

    Joined:
    Jan 12, 2014
    Posts:
    33
    Work:this.gameObject.SetActive (false);

    Doesn't work: this.gameObject.SetActive (true);

    how to make game object active with script?
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
  3. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Are you trying to have the GameObject set itself to active? As far as I know, that's impossible. Once the GameObject is inactive, all attached scripts on it stop running. You have to have another script on a different GameObject set it back to active.
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,199
    Setting a script inactive turns off Update and FixedUpdate. It doesn't deactivate the OnTriggerEnter calls and such things - so you could have a collision make the Update function start running.

    I don't see that as something you'd want to do, but it's still possible to set a gameobject active from "the inside".
     
  5. justadeveloper

    justadeveloper

    Joined:
    Jan 12, 2014
    Posts:
    33
    I figured it out already, I make a gameobject on another script that received triggerStat from another script and then set the gameObject true when the triggerStat is true
    Anyway,Thanks for helping me :D