- Home /
I need to know how to make gameobject activate in like 1 minute.Please Help
I need to know how to activate a gameobject over time. For example say my character is in a spaceship and he lands on a base he leaves the spaceship but I don't want him to be able to get back in so I need to know how to activate say a Cube in the spaceships door way so he can't get back in. Don't worry about giving me a specific time I can do that just give me a script to do it unless I can do it without a script.
Answer by BerggreenDK · Mar 25, 2012 at 06:24 PM
You could do this by setting up an "alarm trigger" that generates an event.
You could also do a counter, that when it reaches zero or goes above a certain value, then it changes a boolean for that door or spawns an enemy etc.
You could also just store/save the current time when your player leaves the ship and once he tries to go back in, then check if the current time is "high enough" compared to the "exit time".
You can use DateDiff for such calculations.
I am sorry, but I dont have the time to write the scripts for your question. Try asking in the normal forum for code if you need it. This Answers is more for simple questions that can be answered with a clear answer.
Answer by simonmc · Mar 26, 2012 at 01:06 AM
Attach the following script to the gameobject you wish to activate after a time, then call ActivateAfter(time) with the time in seconds after which you would like to activate the game object.
using UnityEngine;
public class DelayedActivate : MonoBehaviour {
public void ActivateAfter(float time) {
StartCoroutine(ActivateRoutine(time));
}
private IEnumerator ActivateRoutine(float time) {
yield return new WaitForSeconds(time);
gameObject.active = false;
}
}
Your answer
Follow this Question
Related Questions
problem with the digits of my timer 1 Answer
How to delay a line of code. 2 Answers
Convert Timer to HH:MM:SS 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers