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 cubictoast · Nov 14, 2013 at 10:15 PM · guitexturelerpfademathf

How to make a GUITexture fade In?

I'm attempting to have a script fade in the alpha of a GUITexture from 0 to Opaque, yet whenever I run this script, the texture is changed instantly without any interpolation in between. What am I doing wrong?

 #pragma strict
 
 var BookIcon : GUITexture;
 
 function Start () 
 {
     BookIcon.color.a = Mathf.Lerp(0,8,5 * Time.deltaTime);
 }
 
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 tanoshimi · Nov 14, 2013 at 10:56 PM

"What am I doing wrong?" Several things...

  1. You've placed your code in Start(), so you're only setting color.a once. If you want it to fade, you're gonna have to update its value several times, right? Like in an Update() function?

  2. Lerp(a,b,c) returns a value somewhere between a and b, depending on how close c is from 0 to 1. Your value of c is 5 Time.deltaTime*. Deltatime is the amount of time passed since the last frame. So it might be 0.03 one frame, then 0.025 the next, then 0.031 etc. You're then multiplying by 5, which means you're setting BookIcon.color.a to a fairly arbitrary fraction of the way from 0 to 8.

  3. The alpha component of a colour is a floating point value from 0 to 1. Even if you got your lerp to work, you'd be smoothly transitioning from 0 to 8...

  4. And finally, you didn't search before you posted, which meant you didn't find the previous times this question has been answered. Like here: http://answers.unity3d.com/questions/406507/making-guitexture-start-transparent-then-fade-in.html (but put it in Update(), not OnGUI())

Comment
Add comment · Show 1 · 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 cubictoast · Nov 15, 2013 at 12:49 AM 0
Share

Thank you, that cleared up everything, and I appreciate the detailed answer.

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

17 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

Related Questions

Repeat fade in and out 1 Answer

Making a GUI texture fade in and out depending on player proximity with enemy 2 Answers

How to move a texture created from GUI.DrawTexture 1 Answer

GUI.DrawTexture over screen 2 Answers

Gui appear and then fade to black 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