Hey Everyone,
So Im having a problem trying to add a time to my script, where i want the object to disappear after 30 seconds, after it has been activated.
Here is what i have but im still new to this and not quite sure how to add the time factor to it.
Any advice on this?
Here is the script i have
var open = false;
var activated = false;
function Update(){
if (Input.GetKeyDown("x")){
activated = true;
}
if (activated && !open && Input.GetButtonDown("Fire2")){
animation.Play();
open = true;
}
}
Well you have two choices:
The easiest way would be to delete it with a time limit, but then it might vanish while it was animating.
That would look like this:
var open = false;
var activated = false;
function Update(){
if (Input.GetKeyDown("x")){
activated = true;
Destroy(gameObject, 30);
}
if (activated && !open && Input.GetButtonDown("Fire2")){
animation.Play();
open = true;
}
}
If you want it to not happen while it is animating - this should do it:
var open = false;
var activated = false;
var startTime : float;
function Update(){
if (Input.GetKeyDown("x")){
activated = true;
startTime = Time.time;
}
if (activated && !open && Input.GetButtonDown("Fire2")){
animation.Play();
open = true;
}
if(activated && !animation.isPlaying && (Time.time - startTime) > 30)
{
Destroy(gameObject);
}
}
Thankyou, I can see how this works
Appreciate the help 