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 CrossBlade · May 28, 2013 at 02:13 PM · destroyyieldwaitforseconds

About removing the backlight of a button after a set of time

Hello, I'm working on an on screen keyboard. Currently my problem is that I want to remove the backlight of a button that's been selected after 1 or 2 second(s). I've tried the "Destroy" function and "Yield", but neither works well. I know it's my own problem but can somebody give me some hints? Really no ideas now...... Thanks very very very very much~!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · May 28, 2013 at 02:50 PM

Should the highlight on button 1 immediately snap off if someone quickly presses button 2? In other words, will there only ever be one highlight? Or will quickly pressing buttons 1,2,3,4 give me a delayed effect "wink out 1", "wink out 2" ... ? Are the buttons all the same size?

If only 1 highlight ever and all same size, can make a single traveling highlight. A cheap way to wink out is to store "lastMovedtime," reset it to current time at each move, and check in Update if the lastMovedTime was over 2 seconds ago. Instead of destroying it, can set it inactive, or disable the renderer (or teleport it to -999.)

If you need a highlight for each button, you could also use that trick (every single button would have its own lastClickedTime and a script checking it.) Or, if you go the yield route, look up Coroutines. Yields can only be used in them. They let you say fire&forget things like "turn this off in 2 seconds." But, you'll have to worry about someone clicking a button again after 1.8 seconds (method#1 will just bump up lastClickedTime, so will work.)

Comment
Add comment · Show 8 · 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 CrossBlade · May 28, 2013 at 03:56 PM 0
Share

First, thanks anyway. $$anonymous$$y situation is like the first one, but still I'm a little confused... Can you explain more to me, please? THX!~

avatar image Owen-Reynolds · May 28, 2013 at 05:17 PM 0
Share

What do you have so far? Break it into parts and test each one.

How to make a highlight (plane w/trans texture, or new button texture.) How to move or turn on/off things. How a script can "know about" other objects. Using Time.time as a stopwatch.

avatar image CrossBlade · May 29, 2013 at 09:52 AM 0
Share

Actually, I use GUI.DrawTexture to make a blue background as a backlight. I also use if (i == selectedButton && Input.mousePosition.x > Screen.width/2 - OnScreen$$anonymous$$eyboard.maxWidth2/2 && Input.mousePosition.x < Screen.width/2 + OnScreen$$anonymous$$eyboard.maxWidth2/2 && Input.mousePosition.y < OnScreen$$anonymous$$eyboard.maxHeight2) to judge if the mouse is on the button or not.

avatar image Owen-Reynolds · May 29, 2013 at 10:40 PM 0
Share

DrawTexture is funny -- it's not persistent, so you don't turn it off. Ins$$anonymous$$d, you just stop saying to draw it. Typically with if(drawHighlight) GUI.DrawTexture.... Then drawHighlight controls whether you show it this frame, or not.

But again, "How do I not draw a GUI-item" is a common topic.

avatar image CrossBlade · Jun 17, 2013 at 04:08 PM 0
Share

I see... Do you mean I have to "draw" it again so I can cover the previous one and get a new one?

Show more comments
avatar image
0

Answer by llSalvationll · May 28, 2013 at 04:07 PM

Can't you just use Invoke? Setup a function to have invoked after a few seconds that will turn off the lit key.

http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.Invoke.html

Comment
Add comment · Show 4 · 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 CrossBlade · May 29, 2013 at 09:54 AM 0
Share

Thanks, is works like "Yield". But "Invoke" can only count the time immediately after running the project (is that right?), while "Yield" seems more "free". I'll try the one with "Yield" again.

avatar image llSalvationll · May 29, 2013 at 01:44 PM 0
Share

Yield requires a co-routine, invoke does not. In the logic that handles your button press use something like this: invoke("removeBackLight", 2);. Then in your removeBackLight script (or whatever you call it) disable the light. If a new/different button is pressed, change the back light to the new key, cancelInvoke and then re-invoke to start the timer over. There's a million ways to get the effect you want, so use whatever you find most appealing.

avatar image CrossBlade · May 29, 2013 at 02:49 PM 0
Share

That's really inspiring! I'll try it immediately, THX again!

avatar image Owen-Reynolds · May 30, 2013 at 04:20 AM 0
Share

Yes, Invoke is a coroutine shortcut. It has a single built-in yield.

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

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiate an object as soon as another object is destroyed 2 Answers

Yeild and WaitForSeconds and Instantiate 1 Answer

Destroy then Clone Help please? 2 Answers

Obj calls function, on another obj and get's destroyed. Function stops 1 Answer

Why Is yield return new WaitForSeconds() not working 2 Answers


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