I'm working on a unity game where I want to change the color of a material from within a script. The material applies to a line renderer.
I currently have the following script:
using UnityEngine;
using System.Collections;
public class LaserProperties : MonoBehaviour {
public Vector3 RGBStrengths;
public LineRenderer lineRenderer;
/*
* returns the color in RGB.
*/
Color getColor(){
Color c = new Color (0, 0, 0, 1);
float highest = Mathf.Max (RGBStrengths.x, RGBStrengths.y, RGBStrengths.z);
c.r = RGBStrengths.x / highest;
c.g = RGBStrengths.y / highest;
c.b = RGBStrengths.z / highest;
return c;
}
/*
* returns the total amount of energy in the beam
*/
float getStrength(){
return RGBStrengths.magnitude;
}
void Update(){
updateBeam ();
Debug.Log (getColor());
}
/*
* set color of the beam to the color of the laser
*/
public void updateBeam(){
lineRenderer.SetWidth (getStrength (), getStrength());
lineRenderer.material.color = getColor ();
lineRenderer.material.SetColor ("_Albedo", getColor ());
lineRenderer.material.SetColor ("_Emission", getColor ());
}
}
And here is the material
.
However changing the properties does not result in any chance to the material in question.
Any idea what I'm doing wrong?