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 /
  • Help Room /
avatar image
0
Question by Mindzi · Dec 02, 2016 at 02:17 PM · textlerpalpha

Survival shooter text fade in

Hello I recently finished Survival shooter tutorial and I came across some problem. I want my game over text to fade in after i die so i wrote this into my update function Color targetColor = new Color(255, 0, 0, 255);

     if(isDead)
     {
         gameOver.color = Color.Lerp(gameOver.color, targetColor, 5f * Time.deltaTime);
        
     }

the output of this is that there is no linear transition between color with no alpha and targetColor with alpha 255. What am I missing ? What is solution to make gameOver text slowly appear for 5 second after isDead condition is true ? Thank you all for help

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
1
Best Answer

Answer by hexagonius · Dec 02, 2016 at 02:46 PM

The last parameter of the Lerp works like a slider with 0 choosing the first parameter 100% and 1 the second 100%. If deltaTime was constant like fixedDeltaTime is and it nearly is, you're basically passing in a constant and the resulting alpha is the same value every frame. What you need to do is have a float variable somewhere with a value of 0, increasing it every frame. So in your if statement you would put something like

 yourFloat += Time.deltaTime / 5f;

this will increase yourFloat by a 5th of the passed time every frame essentially setting it to 1 and larger after 5 seconds.

Comment
Add comment · Show 2 · 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 Mindzi · Dec 02, 2016 at 03:25 PM 0
Share

Looks reasonable, but still doesnt work for me. I've tried to put in one more if statement to check if my float reach 5f, but it still fade in(respect. change color in this code) immediately after the isDead condition is made

if(isDead) alphaUp += Time.deltaTime/5f; if(alphaUp >= 5f) { gameOver.color = new Color(255, 0, 0, 255); } //gameOver.color = Color.Lerp(gameOver.color, targetColor, alphaUp);

avatar image Mindzi · Dec 02, 2016 at 03:47 PM 0
Share

Oh sorry that was mistake from my side ( and it was really dumb one ) I forgot to comment on line of code that cause to immediately change the alpha. It was outside this block of code. Really thank you for your help!

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

81 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 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

Make color pulse every 2 seconds 1 Answer

Text Objects do Lerp 0 Answers

How can I change the alpha value of multicolored text to 0? 1 Answer

UI button - 0 alpha response. 0 Answers

[SOLVED] Sprite renderer does not render transparent parts of texture 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