Search Unity

How to get a trigger to turn on when an object turns off

Discussion in 'Scripting' started by Psylova, Dec 3, 2019.

  1. Psylova

    Psylova

    Joined:
    May 5, 2016
    Posts:
    7
    Hey guys. Like the title says, I'm trying to get a trigger to be enabled once a specific object turns off. I have it set up so that when you press E on a yellow cube, the cube will disappear, and a door across map will become unlocked. I want to make it so that an animation will play so that a message will pop up on the bottom left, giving the player the quest to go through the door. The animation, door and cube are all working, but I can't get the trigger to turn on once the object turns off.

    I tried searching around the internet for other solutions, unfortunately I can't seem to find anything. I will be happy to elaborate with screenshots if need be. I'm very new to programming and this is a learning experience for me, so I would appreciate any guidance.

    Thank you.
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    You might want to consider doing the thing when the user presses the button to make the cube disappear, rather than making the cube itself responsible for doing the thing.

    But if you want an object to do something when it is "turned off", you probably want to write a MonoBehaviour with an OnDisable function and attach it to that object. (Though note that I am making assumptions about what you mean by "turn off", since that is not a term of art. OnDisable will run if the object is made inactive or destroyed. If you are making it "disappear" in some other way, like modifying its color, then this might not be suitable for you.)
     
  3. Psylova

    Psylova

    Joined:
    May 5, 2016
    Posts:
    7
    Thanks so much! This really fixed my issue!