Question by
NotTrollax · Dec 28, 2020 at 06:16 AM ·
c#unityeditor
How can I get a raycast to differentiate between the same object?
I am raycasting from the camera to the player and when it hits an item tagged as a wall it sets the mesh render to false and true if it isn't. The problem I have is when the raycast hits a wall and transfers to another wall only the second wall turns back on.
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity) )
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
if (hit.point.z <= player.transform.position.z && hit.collider.tag == "Wall")
{
wall = hit.collider;
//wall.GetComponent<MeshRenderer>().enabled = false;this is done in the script on the wall
wall.GetComponent<WallProperties>().invisible = true;
}
else
{
// wall.GetComponent<MeshRenderer>().enabled = true; this is done in the script on the wall
wall.GetComponent<WallProperties>().invisible = false;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613022220im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How could i save a variable called by multiple objects using the same script? 1 Answer
Vuforia, C# rotating an object to point another object fixing Y Axis 0 Answers
Namespace inside DLL file 0 Answers
My Unity.exe deleted (Unity 2019.3.11),My Unity.exe was deleted (Unity 2019.3.11) 1 Answer
I tried fixing "Using GUiTexture has been removed, use UI.Image instead" But it wont work 1 Answer