I would “reset” all the gameobject’s transparency to 100% DIRECTLY before you set the specific object’s transparency that you need. This could be the following script (placed at the very top of the update script
GameObject[] Walls = GameObject.FindGameObjectsWithTag("Wall");
foreach (GameObject item in Walls) {
item.GetComponent<Renderer>().material.color = new Color(1,1,1,1);
}
This resets all the walls before the camera sets the specific ones that it needs to be transparent
(This is the problem that was occuring) The Camera’s “hit” tag would ALWAYS either be the player or a wall that NEEDED to be set to 50% transparency, so the following script would only come up when the camera has a direct line of sight to the player, in which the “hit” would always be the player
Script portion that would only occur if the camera had direct line of sight to player, and only affected the “hit” object of the player
else
{
Debug.Log("Far");
block = hit.collider.gameObject;
block.GetComponent<Renderer>().material.color = new Color(1, 1, 1, 1);
}
As of the ray casting and only SOME walls changing problem
Your “Debug Ray” and your “Lading Ray” are hitting TWO different positions
Ray LandingRay = new Ray(transform.position, Vector3.forward);
// Landing Ray is showing directly forward of the camera
Debug.DrawRay(transform.position, Direction * Distance);
// Debug Ray is going between the player and the camera
You need to set them to the SAME ray, which could be the following code
Ray LandingRay = new Ray(transform.position,player.transform.position - transform.position);
This way the script is going by the same ray that is being displayed by the Debug Ray