I’m trying to make a script that disables the mesh renderers of objects that are between the player and the camera, so that if the camera moves through a wall, the player is still visible, since the object will be invisible (but still active). I’ve created a Physics.Raycast, but it isn’t detecting walls that go between the player and the camera. Here’s the script:
void FixedUpdate ()
{
//reenable all object renderers that have been disabled
if (disabledObjects.Count > 0)
{
Debug.Log ("list had at least one object in it");
foreach (GameObject gObject in disabledObjects) {
Renderer rend;
rend = gObject.GetComponent <Renderer> ();
rend.enabled = true;
}
}
//clear the list, setting up to be refilled by new objects between camera and player.
Debug.Log ("clearing list");
disabledObjects.Clear ();
//while loop to ensure each object detected by the raycast is disabled
RaycastHit hitInfo;
while (Physics.Raycast (transform.position, target.transform.position, out hitInfo))
{
Debug.Log ("there was something between the camera and the target");
Renderer rend;
rend = hitInfo.collider.GetComponent <Renderer> ();
rend.enabled = false;
disabledObjects.Add (hitInfo.collider);
}
}
What did I do wrong?
I’m pretty much completely new to Unity, please don’t eat me if this is a stupid question.