Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 KristofferH · Jun 03, 2016 at 01:06 PM · guicoroutineanimated

Animate GUI elements by code?

I have a user interface with a info button, when you press it a text box should animate forward, by animating the scale of it, so it "grows out". I've done this by using coroutines that animates the scaling with Lerp. The problem is that if you press the button twice you get strange behaviors; it's like the courotines stacks up and plays again and again. I've tried using StopCoroutine("AnimateScale") and StopAllCoroutines() to abort the first animation but it didn't work.

So how would you animate your GUI elements with code? Should I just move all the animation code in to the Update() method and control it with Booleans wheater the animation should be playing or not? The problem then is that the code needs to check every frame if it should animate or not, and most of the time it shouldn't animate (it's not a button that you should need to press very often), so it sounds like a waste of performance. That's way I looked into coroutines, for performance, but they don't seam to give me the control I need. Since I need to be able to abort or reverse the animation at any time.

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 HarshadK · Jun 03, 2016 at 01:12 PM 0
Share

It would be helpful if you post your code.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Zodiarc · Jun 03, 2016 at 01:20 PM

Why the hassle with animating it by code? It's much easier using animation controllers and the unity animation system. >ou setup your state machine and within your code you can switch the states as you want.

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 KristofferH · Jun 03, 2016 at 01:28 PM 0
Share

With code I can dynamically change the size of the textbox depending on how much text it needs to fit.

avatar image Zodiarc KristofferH · Jun 03, 2016 at 01:32 PM 0
Share

I think this also can be done by the UI system itself. You can also use a scrollview if it shouldn't be possible. Here's an example in my current project how a scroll view behaves:

https://www.youtube.com/watch?v=qrXYOgYQcg0

And a 10 secons google search revealed the following: http://docs.unity3d.com/$$anonymous$$anual/HOWTO-UIFitContentSize.html

avatar image KristofferH Zodiarc · Jun 06, 2016 at 12:35 AM 0
Share

I will look into what the UI system can do itself before I go back to the code :)

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

68 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Making a real coroutine 3 Answers

How to make a GUI button 1 Answer

Animated GUITexture based on Sprite Sheet? 0 Answers

GUI help ! 1 Answer

Fading out GUI Label using coroutine problem 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