Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Scripted transparent object (HDRP/LIT Shader)

MenithMenith Member
edited June 2020 in Programming

Hi, I have an object (e.g. Cube) made a material, Surface Type Opaque and Base Color #898585 (as an example). Now I want to have the object sometimes transparent and then fade it back to opaque.

 

I tried the following.

	Renderer rend = this.transform.GetComponent<Renderer>();
	Material material = rend.material;
	Color oldColor = material.color;
	material.SetFloat("_SurfaceType", 1.0f);
	material.SetColor("_BaseColor", new Color(oldColor.r, oldColor.g, oldColor.b, 0.3f);

 

This does not change anything on the object.

If I just change the last line:

          material.SetColor("_BaseColor", new Color(1.0f, 0.0f, 0.0f, 0.3f));

then at least the cube is red but not transparent.

What do I miss? Is there a need to set values for _Blend, RenderType, _SrcBlend etc. too?

Any ideas or hints? Thank you!!

Sign In or Register to comment.