Particle Add + Fade In/Out

So I’m using the standard Particle Add shader and want to be able to fade the object in and out with a call like this:

renderer.material.color = new Color(0,0,0,0);

But that apparently has no affect on this particular shader. Can someone suggest how to modify it to allow for fading through script.

Thanks a bunch!

Where are all the Shader gurus? :wink:

Shader "Sprite/Additive" {
	Properties {
		_Color ("Main Color", Color) = (1, 1, 1, 1)
		_MainTex ("Texture", 2D) = "white" {}
	}
	SubShader {
		Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
		AlphaTest Greater .01
		Blend SrcAlpha One
		ColorMask RGB
		Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
		Pass {
			SetTexture [_MainTex] {
				constantColor [_Color]
				combine constant * texture
			}
		}
	}
}

Thanks so much! I’ll try this out as soon as I squash a few lingering bugs from my Unity 3 upgrade.

For some reason, the built-in particle shaders use _TintColor instead of _Color (which maps to material.color).

You should be able to do:

renderer.material.SetColor("_TintColor", new Color(r, g, b, a));

Yeah, after a few hours of flailing about I figured that out!

Tried the above shader, and very much appreciate the effort, but it didn’t work as I wanted. Seems to function differently than Particle Add. Or maybe I’m just using it wrong. My guess is it treats my texture (which doesn’t have an alpha) differently.

The built-in additive shader doubles the result. You can add " DOUBLE" to the end of the combine line to have my shader do the same.