Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using lerp and alpha

Discussion in 'Scripting' started by robertseadog, Nov 30, 2005.

  1. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    Hi im having a slight difficulty in fading several objects at once..

    Im using this script with the new beta :
    Code (csharp):
    1.  
    2. /*another function*/
    3. for (var child : Transform in initiateCrack.transform) {
    4.         (child).gameObject.AddComponent ("Rigidbody");
    5.         fadeColors((child).renderer);
    6.     }
    7. /*end of other function*/
    8. function fadeColors (objectRenderer) {
    9.  
    10.     while (objectRenderer.material.color.a > 0.1) {
    11.         var fadeColor : Color = objectRenderer.renderer.material.color;
    12.         fadeColor.a = 0.0;
    13.         objectRenderer.renderer.material.color = Color.Lerp (objectRenderer.renderer.material.color, fadeColor, 0.1* Time.deltaTime);
    14.         yield;
    15.     }
    16. }
    I though the alpha thing was to be resolved in this build? Or am I doing something wrong? Im using a aplha/glossy shader on the "child" objects..

    When I try it it simply turns to 0, no fade!
     
  2. aaronsullivan

    aaronsullivan

    Joined:
    Nov 10, 2005
    Posts:
    986
  3. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    ah I knew about that actually, thanks for pointing ithat out!
    I edited your code to please the compiler ;)
    Code (csharp):
    1.  
    2. StartCoroutine ("fadeColors","((child).renderer)");
    3.  
    Hmm.. Can't find variable material?
    Code (csharp):
    1.  
    2.     for (var child : Transform in initiateCrack.transform) {
    3.         (child).gameObject.AddComponent ("Rigidbody");
    4.         StartCoroutine ("fadeColors","((child).renderer)");
    5.     }
    6. //---------------------------------
    7. function fadeColors (objectRenderer) {
    8.  
    9. while (objectRenderer.material.color.a > 0.1) {
    10.         var fadeColor : Color = objectRenderer.material.color;
    11.         fadeColor.a = 0.0;
    12.         objectRenderer.material.color = Color.Lerp (objectRenderer.material.color, fadeColor, 0.1* Time.deltaTime);
    13.         yield;
    14.     }
    15. }
    16.  
     
  4. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Feel free to use this JS if it helps you out:
    Code (csharp):
    1. var initialDelay = 1.0;
    2. var fadeSpeed = 0.1;
    3.  
    4. yield new WaitForSeconds(initialDelay);
    5.  
    6. StartCoroutine("Fade");
    7.  
    8. function Fade()
    9. {
    10.     while (renderer.material.color.a > 0.004)
    11.     {
    12.         color = renderer.material.color;
    13.         color.a = 0.0;
    14.         renderer.material.color = Color.Lerp(renderer.material.color, color, fadeSpeed * Time.deltaTime);
    15.        
    16.         yield;
    17.     }
    18.     Destroy(gameObject);
    19. }
     
  5. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
  6. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374