I’m trying to and change the color of a trail renderer. I created this workaround, but I’m running into an odd issue. The material instance’s color is changed in the Unity inspector, but it won’t change color in the game unless I manually use the color picker and change the color (and sometimes, even that does nothing). What am I doing wrong?
var Test: Material;
var MyColors: Color[];
function Start(){
Test = GetComponent.<TrailRenderer>().material;
Test.SetColor ("_TintColor", MyColors[1]);
}
If you remove the . before the <TrailRenderer>
and reformat the variables and start function to c#, this does run as a c# script. I’m not too familiar with javascript, but after checking the Unity reference page for GetComponent, it appears that the javascript version uses the syntax GetComponent( string name)
instead of GetComponent<component>()
. To get your code working, I changed it to the following
var test: TrailRenderer;
var myColor: Color;
function Start () {
test = GetComponent("TrailRenderer");
test.material.SetColor("_TintColor", myColor);
}