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 GileanVoid · Jul 16, 2018 at 09:39 AM · animationtext

How to change text alpha with distance?

Hello! Looks simple, but there is complication. I have a canvas over object with animated UI text - animation already changes its alpha so text becomes transparent over time. And ALSO I need it to slowly vanish when player is too far. What is the best way to get it done?

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

Answer by Stratosome · Jul 16, 2018 at 09:50 AM

Well, one idea you could try is to have a "max distance" that the player can walk from the object until the canvas is fully invisible. Get the current distance from the player and do something like (currentDist/maxDist) to get a percentage. This can be your distanceAlpha. Now you have two potential alpha values for the canvas (distanceAlpha and timerAlpha). Pick whichever one is the greatest (or least depending on how you do it) and apply only that alpha to the canvas.

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 Stratosome · Jul 16, 2018 at 09:52 AM 0
Share

Although I guess I assumed that when you said animated UI text, it was perhaps a coroutine handling that. If it is Unity's animation system ins$$anonymous$$d, it may be a bit different.

avatar image GileanVoid Stratosome · Jul 16, 2018 at 09:57 AM 0
Share

@Stratosome and @tormentoarmagedoom, thanks for your answers! Yes, its animation system. Its like, you know, damage number, that fly away from enemy after hit, and vanish in the air. I achived that with animator. And now I need it to be visible for player only in close distance.

avatar image Stratosome GileanVoid · Jul 16, 2018 at 10:08 AM 0
Share

Ah, gotchya. Hrmm, I'm not quite sure the best way to get the animation's alpha and the distance alpha to interact nicely when using the animator. Personally, I'd just use a coroutine ins$$anonymous$$d of the animator to put a little timer on the text that pops up. You'd have more control over it too in code.

 private IEnumerator TextAlphaTimer(float duration) {
     float elapsedTime = 0;
     while (elapsedTime < duration) {
         float percentageComplete = (elapsedTime / duration);
 
         // Update text alpha here
         // ...
 
         elapsedTime += Time.deltaTime;
         yield return null;
     }
 
     // Timer is complete
     // ...
 }
Show more comments
avatar image
1

Answer by tormentoarmagedoom · Jul 16, 2018 at 09:46 AM

Good day.

You need to do it by code, not by animation.

You just need to use

 float distance == Vector3.Distance(position1, position2);

and then change the color depending ont he distance value by:

 float TheAlphaValue = (Here you must calculate what alfa you want related to distance value)

 Text.color = new Color (text.color.r, text.color.g, text.color.b, TheAlphaValue);

Try it, look for tutorials to understand everything, and try try try!

Bye!

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

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

How can i pay a animation again and agan? 1 Answer

Animating Transitions for GUI Results 0 Answers

Can the animation editor create local rotational data? 3 Answers

Adding animation clips via script 2 Answers

UI text animation 0 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