Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

iTween - How can i change trail color ?

Discussion in 'Scripting' started by veri, May 7, 2012.

  1. veri

    veri

    Joined:
    Apr 21, 2012
    Posts:
    4
    I can change trail color by :

    Code (csharp):
    1. gameObject.GetComponent<TrailRenderer>().material.SetColor("_TintColor",color);
    I can change object color by :

    Code (csharp):
    1. iTween.ColorTo(gameObject,iTween.Hash("color",color,"time",0.1f,"includechildren",true));
    But i don't know how to change a component's color in itween ?

    Somebody has some tricks ?
    Can i make a mat 'static' so i put my mat on an hidden object ?
     
  2. adamjamescuz

    adamjamescuz

    Joined:
    Oct 29, 2012
    Posts:
    6
    Hi - maybe too late for you now but in case it helps anyone else - you can just use itTween.ValueTo. For example, to fade from 0 to 1, set the 'from' and 'to' params to 0 and 1, set the 'onupdate' callback function and in there set the trail material's alpha directly using the value parameter.

    Code (csharp):
    1. Hashtable args = new Hashtable();
    2. args.Add("from", 0);
    3. args.Add("to", 1);
    4. args.Add("time", 2);   
    5. args.Add("onupdate", "updateTrailAlpha");      
    6. iTween.ValueTo(gameObject, args);
    And then (this example does it for the tint color as most people use an additive material with transparency for trail materials):

    Code (csharp):
    1. void updateTrailAlpha(float val)
    2.     {
    3.         TrailRenderer tr = gameObject.GetComponent<TrailRenderer>();
    4.         Color c = tr.material.GetColor("_TintColor");
    5.         c.a = val;
    6.         tr.material.SetColor("_TintColor", c);
    7.     }
     
  3. justinl

    justinl

    Joined:
    Aug 27, 2012
    Posts:
    58
    Another way to achieve it is to add a light to the object that your script is on, disable the light, and then iTween.ColorTo() the light color, and then set your component colour to be the same as the light. This is basically using the Light as a dummy object.
     
  4. ReadPan_

    ReadPan_

    Joined:
    Jan 23, 2015
    Posts:
    4
    Thanks, its helpful!