How would I use other.gameobject like I've seen in collider scripts? to work in my camera script
So, I want my camera to detect a object in-front of it and if it is... lets say, 30 meters in-front of it, the opacity of the wall in-front of it to 50%. How would I do that? This is how I imagined it to work
void Cam(IsVisible other)
{
if(other.gameobject.transform-Camera.transform <= 30 && other.gameobject.comparetag("wall"))
{
other.GetComponent<MeshRenderer>().material.color = new Color(1.0f, 1.0f, 1.0f, 0.5f);
}
else
{
other.GetComponent<MeshRenderer>().material.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
}
}
Could you help me Make a piece of code that would actually work because I am fairly new to unity, Ik how I want it to work but I don't know how to make it work
You already have the "receiver" code, now you need the "broadcaster" code. You may use RayCast, or simply this if your objects have Renderers.
Ok so I made a change
void OnBecomeVisible(Cam other) { if (other.gameobject.transform - transform <= 30 && other.gameobject.comparetag("wall")) { other.GetComponent<$$anonymous$$eshRenderer>().material.color = new Color(1.0f, 1.0f, 1.0f, 0.5f); } else { other.GetComponent<$$anonymous$$eshRenderer>().material.color = new Color(1.0f, 1.0f, 1.0f, 1.0f); } }
what do I put in the () in OnBecomeVisible