Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Keavon · Jan 02, 2011 at 11:32 PM · guitextdestroytimeremove

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!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jessy · Jan 03, 2011 at 12:44 AM 0
Share

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Jessy · Jan 03, 2011 at 12:43 AM

Destroy(GameObject.FindWithTag("Tag Goes Here"), destroyDelay);

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

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jesus_Freak · Jan 03, 2011 at 01:28 AM 0
Share

he did say simple, though!

avatar image Jesus_Freak · Jan 03, 2011 at 01:40 AM 0
Share

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

avatar image Keavon · Jan 04, 2011 at 01:45 AM 0
Share

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!

avatar image
1

Answer by Jesus_Freak · Jan 03, 2011 at 12:26 AM

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jesus_Freak · Jan 03, 2011 at 12:32 AM 0
Share

this is a unityscript.

avatar image Jessy · Jan 03, 2011 at 12:50 AM 0
Share

There are 60 seconds in an Earth $$anonymous$$ute, not 100. $$anonymous$$ultiplying 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().

avatar image Jesus_Freak · Jan 03, 2011 at 01:27 AM 0
Share

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 $$anonymous$$ute. 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 $$anonymous$$ute.

avatar image Jesus_Freak · Jan 03, 2011 at 01:38 AM 0
Share

Time.deltaTime is what makes that possible. and that already does the 60seconds = 1$$anonymous$$ute 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 $$anonymous$$ute, and 1000.00 is ten $$anonymous$$utes.

avatar image Jessy · Jan 03, 2011 at 02:02 AM 0
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Delay Gameplay While Displaying 3,2,1 go!!! 3 Answers

Destroy text 1 Answer

How to draw GUI Text from code 1 Answer

How to make GUI Text appear after a certain amount of time 2 Answers

GUI Button appears when Paused 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges