Question by
junaidy123 · Jan 23 at 01:34 PM ·
physics.raycast
Why is Physics.Raycast still execute even when the statement doesn't match the if condition
I'm running this code in update, to replacing "OnMouseDown()", using the new InputSystem, but the object still return the name while the "isPlaceable" bool is false, why is this happening ?
[SerializeField] bool isPlaceable;
if (Mouse.current.leftButton.wasPressedThisFrame && IsPlaceable)
{
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
RaycastHit hit;
bool rayHit = Physics.Raycast(ray, out hit, Mathf.Infinity);
if (rayHit)
{
Debug.Log(hit.transform.name);
}
}
Comment
Your answer
Follow this Question
Related Questions
Raycast ignoring InvokeRepeating intervals 0 Answers
Identifying objects in a stack 1 Answer
In game, get object at mouse position or screen point without using a collider 0 Answers
I need to know how to spawn a prefab and then have it propelled forward as if thrown 0 Answers
Physics.Raycast is not working with VR 0 Answers