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 calibex · Oct 03, 2012 at 03:26 AM · fade3d text

Fading 3d text - only fades once

Hello all, first off thanks in advance.

But I have looked at how to do this on many forum posts and I think I created the code correctly. The issue is it seems to fade over say 2 seconds once without issue but from then on it will just have a 2 second delay and blink on or off. The goal of the code is to fade in and out at a certain range from the camera.... Seems simple but I have no idea what would cause this to just work once and stop after that... Any help would be greatly appreciated. Thanks again.

Script on 3d text:

 var Range = 30.0;
 var target : Transform;
 var _time:float;
 
 function Update ()
 {
    if (Vector3.Distance(transform.position, target.position) > Range){
        Fade.use.Alpha(GetComponent(TextMesh).renderer.material,1.0,0.0,_time, EaseType.In);
     }
 
 if(Vector3.Distance(transform.position, target.position) < Range){
        Fade.use.Alpha(GetComponent(TextMesh).renderer.material,0.0,1.0,_time, EaseType.Out);
     }
 }

Script on Fade.js:

 function Awake () {
     if (use) {
         Debug.LogWarning("Only one instance of the Fade script in a scene is allowed");
         return;
     }
     use = this;
 }
 
 function Alpha (object : Object, start : float, end : float, timer : float) {
     yield Alpha(object, start, end, timer, EaseType.None);
 }
 
 function Alpha (object : Object, start : float, end : float, timer : float, easeType : EaseType) {
     if (!CheckType(object)) return;
     var t = 0.0;
     var objectType = typeof(object);
     while (t < 1.0) {
         t += Time.deltaTime * (1.0/timer);
         if (objectType == GUITexture)
             (object as GUITexture).color.a = Mathf.Lerp(start, end, Ease(t, easeType)) * .5;
         else
             (object as Material).color.a = Mathf.Lerp(start, end, Ease(t, easeType));
         yield;
     }
 }
 
 function Colors (object : Object, start : Color, end : Color, timer : float) {
     yield Colors(object, start, end, timer, EaseType.None);
 }
 
 function Colors (object : Object, start : Color, end : Color, timer : float, easeType : EaseType) {
     if (!CheckType(object)) return;
     var t = 0.0;
     var objectType = typeof(object);
     while (t < 1.0) {
         t += Time.deltaTime * (1.0/timer);
         if (objectType == GUITexture)
             (object as GUITexture).color = Color.Lerp(start, end, Ease(t, easeType)) * .5;
         else
             (object as Material).color = Color.Lerp(start, end, Ease(t, easeType));
         yield;
     }
 }
 
 function Colors (object : Object, colorRange : Color[], timer : float, repeat : boolean) {
     if (!CheckType(object)) return;
     if (colorRange.Length < 2) {
         Debug.LogError("Error: color array must have at least 2 entries");
         return;
     }
     timer /= colorRange.Length;
     var i = 0;
     var objectType = typeof(object);
     while (true) {
         var t = 0.0;
         while (t < 1.0) {
             t += Time.deltaTime * (1.0/timer);
             if (objectType == GUITexture)
                 (object as GUITexture).color = Color.Lerp(colorRange[i], colorRange[(i+1) % colorRange.Length], t) * .5;
             else
                 (object as Material).color = Color.Lerp(colorRange[i], colorRange[(i+1) % colorRange.Length], t);
             yield;
         }
         i = ++i % colorRange.Length;
         if (!repeat && i == 0) break;
     }   
 }
 
 private function Ease (t : float, easeType : EaseType) : float {
     if (easeType == EaseType.None)
         return t;
     else if (easeType == EaseType.In)
         return Mathf.Lerp(0.0, 1.0, 1.0 - Mathf.Cos(t * Mathf.PI * .5));
     else if (easeType == EaseType.Out)
         return Mathf.Lerp(0.0, 1.0, Mathf.Sin(t * Mathf.PI * .5));
     else
         return Mathf.SmoothStep(0.0, 1.0, t);
 }
 
 private function CheckType (object : Object) : boolean {
     if (typeof(object) != GUITexture && typeof(object) != Material) {
         Debug.LogError("Error: object is a " + typeof(object) + ". It must be a GUITexture or a Material");
         return false;
     }
     return true;
 }
  
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 Eric5h5 · Oct 03, 2012 at 04:20 AM

You're starting a new instance of the Fade routine every frame. You should call it once only, until it's finished. Either don't use Update (e.g., use a trigger with OnTriggerEnter/Exit), or else add logic so that it's only called once when needed and not every frame.

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 calibex · Oct 03, 2012 at 08:28 AM 0
Share

Thank you for the answer, I adjusted my code below, now using triggers and a collider box... no luck though, been messing with the options but struggling.. sigh... am I missing something with the code by any chance?

var _time:float;

function OnTriggerEnter (other : Collider)

{

    Fade.use.Alpha(GetComponent(Text$$anonymous$$esh).renderer.material,1.0,0.0,_time);


}

function OnTriggerExit (other : Collider)

{

    Fade.use.Alpha(GetComponent(Text$$anonymous$$esh).renderer.material,0.0,1.0,_time);

}

avatar image calibex · Oct 03, 2012 at 08:37 AM 0
Share

Yup, Im retarded... and tierd... This did work, just forgot to add a collider to the text. Thanks for the 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

10 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

Related Questions

Fading 3D Text 1 Answer

Fade in 3d Text 2 Answers

Fade 3d text with lerp? 1 Answer

How to make 3D text fade with OnMouseEnter? 1 Answer

Fading all but single instance of a button 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