x


Script to make a GUI texture disappear after a set amount of seconds?

Hi. I need a very simple script that will destroy a game object with a set tag after a certain amount on time set in a variable. Thank you!

more ▼

asked Jan 02 '11 at 11:32 PM

Keavon gravatar image

Keavon
358 30 34 44

If you just need any Game Object destroyed, please change your title and edit your tags to get rid of the irrelevant references.

Jan 03 '11 at 12:44 AM Jessy
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first
Destroy(GameObject.FindWithTag("Tag Goes Here"), destroyDelay);

http://unity3d.com/support/documentation/ScriptReference/Object.Destroy.html

more ▼

answered Jan 03 '11 at 12:43 AM

Jessy gravatar image

Jessy
15.6k 72 95 196

he did say simple, though!

Jan 03 '11 at 01:28 AM Jesus_Freak

i fixed my code so it will only destroy one time.

Jan 03 '11 at 01:40 AM Jesus_Freak

I think this would work, however I do not need to do what I wanted before, so I won't test it. Sorry. However, thank you for your guy's ideas and input! Thank you also to the one below by Unity3_User. I will give you best answer Jessy because I think that would work easier, but you both deserve points for it!

Jan 04 '11 at 01:45 AM Keavon
(comments are locked)
10|3000 characters needed characters left
var timeToWait : float = 100.00 //this is 1 minute.
var timer : float;//this will change itself
var destroyed = false;
function Update()
{
 //if(otherVar) {
 timer += 1 * Time.deltaTime;
 if(timer >= timeToWait)
 {
  if(!destroyed)
  {
   Destroy(gameObject.FindWithTag("GuiTexture"));
   destroyed = true;
  }     
 }
 //} 
}

i hope this helps, i'm using it to make a "stop game" effect. and the time and all works.

more ▼

answered Jan 03 '11 at 12:26 AM

Jesus_Freak gravatar image

Jesus_Freak
1.2k 38 44 59

this is a unityscript.

Jan 03 '11 at 12:32 AM Jesus_Freak

There are 60 seconds in an Earth minute, not 100. Multiplying something by 1 serves no purpose. Your code will cause errors after the first Destroy(), because it will attempt to Destroy the same object every frame, after timeToWait is up, and that object will no longer exist after the first Destroy().

Jan 03 '11 at 12:50 AM Jessy

it's not adding 1 seconds every seconds, it's adding 1 VALUE every frame. at the rate the frames are called, 10.00 if it was above, would be 1 second. but i agree to the 1 times anything by itself rule. 7th grade math. and the destroy function, but this script makes it somehow, that 100 = 1 minute. try it, turn the timer into a String, GUI.Box(rectInfo, timer.ToString("f0")); and see what happens. compare that to the System.DateTime.Now. then you will see how 100 = 1 minute.

Jan 03 '11 at 01:27 AM Jesus_Freak

Time.deltaTime is what makes that possible. and that already does the 60seconds = 1minute thing, it's adding .03 or there around, every frame, and that makes it so that the 10.00 is 1 second, 100.00 is 1 minute, and 1000.00 is ten minutes.

Jan 03 '11 at 01:38 AM Jesus_Freak

You don't understand Time.deltaTime. Look it up in the docs to see what it means. If you still believe what you have said, after that, please post code above that supports your findings.

Jan 03 '11 at 02:02 AM Jessy
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3695
x764
x573
x555
x91

asked: Jan 02 '11 at 11:32 PM

Seen: 1983 times

Last Updated: Jan 02 '11 at 11:32 PM