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 dmpaskiet · Oct 15, 2010 at 02:37 AM · guitimeguitextureenabledachievement

Removing a GUITexture a set amount of time after it has been enabled.

I've set up a simple achievement structure in my game, basically if the player gets 10 scoring objects without taking any damage they get a "ten in a row" achievement.

I've got it coded so the achievement icon comes up as a GUITexture and it plays a sound with the following code:

guiTexture.enabled = false; var Tada : AudioClip; private var played: boolean = false;

function Update () { if(scorer.scorz == 10 && LifeScript.life == 5 && !played) { played=true; audio.clip = Tada; audio.Play(); } }

What I would like to do and have so far failed at (I'm still in the early learning stages of Javascipt), is have it then disappear after 10 or so seconds so it didn't stay on the screen.

I know the answer is probably really simple, so I apologize for asking a newbie question, but all help is greatly appreciated.

Comment
Add comment
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

1 Reply

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

Answer by Eric5h5 · Oct 15, 2010 at 02:54 AM

Update runs every frame, which is not efficient for something that only happens occasionally, and coroutines are good for scheduling sequences of events. Therefore I'd ditch that and use a coroutine for the score function, which would be in the global scoring script, and you'd call the function whenever you added a point to the score:

var tada : AudioClip; private var played = false; private var score = 0;

function AddScore () { score++; if (score == 10 && LifeScript.life == 5 && !played) { played = true; audio.clip = tada; audio.Play(); guiTexture.enabled = true;

     yield WaitForSeconds(10.0);

     guiTexture.enabled = false;
 }

}

You'd have to reference the GUITexture some other way, unless the score script was on the GUITexture of course.

--Eric

Comment
Add comment · 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

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

guiTexture.enabled (am I an idiot???) 1 Answer

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

Move GUI elements. 0 Answers

GUITexture Button? 1 Answer

What's a great way to make a custom information window pop up 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