I see the same question all over but they’re all talking about sky boxes and shaders.
I have a shield bubble around my ship, and I want it to disappear visually, and reappear when something hits it. I wrote this script here.
public Color myColor;
void Update () {
if (myColor.a > 0)
{
myColor.a -= 0.1f;
}
GetComponent<Renderer>().material.color = myColor;
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Asteroid")
{
myColor.a += 150;
}
}
On runtime, it tells me that the material has no color property. The material is using the particles/additive shader, which has the tint color property. How would I access that property?
When I try the script on the standard shader, it doesn’t even work they way I think it should. When an asteroid hits it, it puts it at 255 alpha instead of 150, and it doesn’t deplete unless I open the color picker tool, which forces it to update I guess. I tried making the color variable private.
Have you tried to manipulate the tint color of the shader directly?
GetComponent<Renderer>().material.SetColor("_TintColor", myColor);
PS: If you have selected your material, you can click on the little gear icon in the inspector and then on Edit Shader. Now you can see which properties the shader has and what their string representation is to access them.
public Color myColor;
void Update ()
{
if (myColor.a > 0)
{
myColor.a -= 0.001f;
}
GetComponent<Renderer>().material.color = myColor;
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Asteroid")
{
myColor.a += 1;
}
}
// use this script and please check if material of your object must have color property
I’m using Unity’s: Particles/Additive shader, and I tried this code,
but i keep getting an error:
Material doesn’t have a color property ‘_Color’
UnityEngine.Material:get_color()
FadeCylinder:MaxAlpha() (at Assets/Wyndham/Sandbox/CocktailTransition/Script/FadeCylinder.cs:47)
c__Iterator1C:MoveNext() (at Assets/Wyndham/Sandbox/CocktailTransition/Script/FadeCylinder.cs:81)
UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
FadeCylinder:FadeIn(Single) (at Assets/Wyndham/Sandbox/CocktailTransition/Script/FadeCylinder.cs:136)
FadeCylinder:FadeIn() (at Assets/Wyndham/Sandbox/CocktailTransition/Script/FadeCylinder.cs:125)
FadeCylinder:Update() (at Assets/Wyndham/Sandbox/CocktailTransition/Script/FadeCylinder.cs:153)