Hello,
I need to make an interaction script. So far it looks like this:
void Update()
{
_Fwd = _Camera.transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, _Fwd, out _Hit, _InteractLenght, _InteractLayer))
{
if (_Hit.collider.CompareTag("Door") || _Hit.collider.CompareTag("Drawer"))
{
_Crosshair_Interact();
if(Input.GetKeyDown(KeyCode.E))
{
//_Hit.collider.GetComponent<ToggleAnimation>().Toggle();
}
}
}
else if (_InteractIconToggle)
{
_InteractIconToggle = false;
Crosshair_Idle();
}
}
However, when I use it for interaction layer it doesn’t count the default layer which means my raycast can go through walls and interact with objects through the wall. Would I have to do a second raycast using a default layer and returning a true if the object is hit in default layer and interact layer? Or is there any more of an efficient way of doing this?
Thank you for your time.