Hi, I was hoping to be able to make an object fade away through code, and to start with, I tried changing the alpha of the object like this gameObject.GetComponent<MeshRenderer>().material.color = new color (1, 1, 1, 0);
But it made no difference.
I was wondering if there’s anything like gameObject.GetComponent<MeshRenderer>().material.shader = Shader.Material.SetActive(false);
that can work? Where you use SetActive?
I got some results with the following code, but my cube, after pressing left mouse button, went PINK. After searching forums, I read about Preferences> GI Cache> Clean Cache, and believing that might help, followed those instructions, but it made no difference.
Still pink when LMB pressed. ![]()
Ideally I would like to be able to change the object from opaque to transparent at afadeFloat * timeDeltaTime, but that was the next part of the problem.
public class Fade : MonoBehaviour
{
GameObject player;
// Use this for initialization
void Start()
{
player = gameObject;
GetComponent<MeshRenderer>().material.shader = Shader.Find("Standard");
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
gameObject.GetComponent<MeshRenderer>().material.shader = Shader.Find("Transparent/Standard");
}
}
}