Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Fading Problems

Discussion in 'Scripting' started by forestjohnson, Apr 22, 2006.

  1. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    Here is a souped up Timed Delete script I made:
    Code (csharp):
    1.  
    2. var emitter = false;
    3. var emitTimeOut = 0.500;
    4. var deleteTimeOut = 1.000;
    5.  
    6. function Awake ()
    7. {
    8.     if(emitter) Invoke ("StopNow", emitTimeOut);
    9.     Invoke ("DestroyNow", deleteTimeOut);
    10. }
    11.  
    12. function StopNow ()
    13. {
    14.         particleEmitter.emit = false;
    15. }
    16.  
    17. var detachChildren = false;
    18.  
    19. function DestroyNow ()
    20. {
    21.     if (detachChildren) {
    22.         transform.DetachChildren ();
    23.     }
    24.     DestroyObject (gameObject);
    25. }
    26.  
    27. var fadeOut = false;
    28. var fadeSeconds = 0.000;
    29. private var timer = 0.0000000000000;
    30.  
    31. function Update ()
    32. {
    33.     timer += Time.deltaTime;
    34.     renderer.material.color.a = timer / fadeSeconds;
    35. }
    36.  
    The fading part at the bottom is where the script is failing. It compiles ok but fails to fade anything out. When I run the game the material changes to an instance of its self but the opacity never changes. I know the object I am using it on can be faded by changing the material opacity.
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    var fadeSeconds = 0.000;

    fadeseconds is set to 0 in your script and then you divide with it.
    Probably not what you wanted.
     
  3. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    I have fadeSeconds set to a divisable number in the inspector. The problem is the trail renderer component I was using with this was over riding my changes. Sadly there is no way to change trail renderer setting on the fly with a script. I guess I want to use the Line Renderer.
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    The trail renderer does not override material properties.
    Generally renderers don't modify material properties.
     
  5. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    Then explain to me why it works on a cube with the same material as the trail renderer but the trail renderer won't work
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    I tried attaching the script to a trail renderer and attaching a diffuse alpha material. Which worked perfectly fine.