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 hollym16 · Mar 19, 2015 at 01:29 PM · animationguibuttonmenuguitexture

Animate GUI Elements

I've got a GUITexture on screen using this code:

 GUI.DrawTexture (new Rect(Screen.width*0f/5f,Screen.height*0.4f/2f, Screen.width* 4f/5f, Screen.height*4f/5f), myObject);

On a button press, I want the texture to animate to the right and go off screen. Basically to go from position 'Screen.width*0f/5f' to 'Screen.width*5f/5f' over 1 sec, for example.

I've seen some plugins that do this but I was wondering if there was a way to just code it; I know the logic just not the right wording for it.

Any Clues?

Comment
Add comment · Show 4
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 Nymisu · Mar 19, 2015 at 01:35 PM 0
Share

There's 2 official unity tutorials on this...

http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-transitions

http://blogs.unity3d.com/2014/06/30/unity-4-6-new-ui-world-space-canvas/

Also, this is absurdly old UI system code. You might find it much more compelling to use the new UI. Far less work, and better results.

avatar image Neamtzu · Mar 19, 2015 at 01:38 PM 0
Share

This something like this:

 float x = 0;
 
 void Update() {
     if(buttonWasPressed && x < 5)
         x = $$anonymous$$athf.Lerp(0, 5, Time.deltaTile);
 }
 
 void OnGUI() {
     GUI.DrawTexture (new Rect(Screen.width * x/5f,Screen.height*0.4f/2f, Screen.width* 4f/5f, Screen.height*4f/5f), myObject);
 }



avatar image hollym16 · Mar 19, 2015 at 02:53 PM 0
Share

Thanks for your answer, I've had a fiddle with the new UI but still having problems with it so better the devil you know! For the time being at least. I've implemented your script like so:

     GUI.DrawTexture (new Rect(Screen.width*x/5f,Screen.height*0.4f/2f, Screen.width* 4f/5f, Screen.height*4f/5f), myObject);
         if(GUI.Button(new Rect(Screen.width*x/5f,Screen.height*0.4f/2f, Screen.width* 4f/5f, Screen.height*4f/5f), "Button"))
         buttonWasPressed = true;
         if(buttonWasPressed && x < 5f)
             x = $$anonymous$$athf.Lerp(0f, 5f, Time.deltaTime);

In play mode it move slightly to the right but not all the way, then it jitters. Any idea what could be causing this?

avatar image Nymisu · Mar 19, 2015 at 03:02 PM 0
Share

It probably jitters because its' position is made on update ins$$anonymous$$d of onGUI. Another reason is that it never actually stops lerping.

Update is tied to the games' refresh rate, while onGUI is tied to GUI's refresh rates, normally you can't tell the difference, but it is there. Just like with update and fixedupdate.

http://docs.unity3d.com/$$anonymous$$anual/ExecutionOrder.html

I'd still want to urge you to try and get more used to the new UI, even if you might have to hit your toes to doorframes with it a couple of times to get over the learning curve. $$anonymous$$ostly because i just created this effect using the animator within 5 $$anonymous$$utes, of which 4 $$anonymous$$utes was booting up Unity and making the button ;)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hollym16 · Mar 19, 2015 at 03:44 PM

I know with the new UI system this is becoming obsolete but for anyone else struggling with Math.Lerp, I found a great link as well as the stuff above:

http://answers.unity3d.com/questions/237294/how-the-heck-does-mathflerp-work.html

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

22 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

Related Questions

Unity 5 GUI system 1 Answer

How do I use my .png file as a button? 1 Answer

guiTexture color half alpha White? 1 Answer

GUI.DrawTexture on GUI.Button press 1 Answer

My GUI buttons are triggering without user input. 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