- Home /
How to make something happen when an object isn't active
Is there a way to trigger something to happen when an object is inactive? For example, if I wanted it so then when I click on an object, it goes inactive (that I can already do). Then I want a level to load after it isn't active (I can't do that). I am trying to do this with two different scripts; one to make the object inactive and one to load the level. Here is the script that loads the level:
var object : GameObject;
function Update(){
if(object.SetActive == false){
Application.LoadLevel("Level");
}
}
Answer by robertbu · Jun 16, 2013 at 07:45 PM
Inactive objects do not get Update() messages. But inactive object do get Invoke() and InvokeRepeating() messages. So you can use either of these to check the active state at some future date.
I'm unclear about what you are doing here. If an inactive object triggers a new level, why not load the level in the code that makes this inactive instead?
I am making a game where you need to collect things. I want it so then when a certain amount of things are collected, a new level loads. That's why I need two separate scripts. I was just using Application.LoadLevel() as an example.
In start you can do something like:
InvokeRepeating("CheckCollectionStatus", 0.0, 0.1);
Then you write a function called CheckCollectionStatus() that checks to see if enough items have been collected. With the values above, it will be called 10 times per second, and it will run on an inactive object.
Your answer
Follow this Question
Related Questions
Level Fade Help! 2 Answers
Wait until audio is finished before set active is false 2 Answers
Activate gameobject that is deactivated with c# 2 Answers
My if statements are not working [major noob] 2 Answers
OnTriggerEnter to load new level 1 Answer