Question by
kotletschabowy · Jun 03, 2020 at 04:19 PM ·
2draycastraycasting
Raycast returns 0 instead of mouse position
Hi, i try to drop objects from ui into 2d world using raycasting. Object is dropped on the good layer but in a wrong place. Dropped item always shows up on coordinates x=0, y=0, z=0 insted of mouse position in world. i know something is wrong, propbably RaycastHit is not defined but im not sure how to fix this and would apreciate some help
public Camera cam;
public virtual void OnDrop()
{
RaycastHit hit = new RaycastHit();
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit));
{
gameObject.SetActive(true);
gameObject.transform.position = hit.point;
}
}
Comment
Your answer
Follow this Question
Related Questions
Raycast on mouse position problem. how not to raycast to 0 1 Answer
Need a Raycast2d to point where my ship is looking 0 Answers
Rigidbody blocking raycasts 2D 0 Answers
Select from multiple character to move 0 Answers
2D raycast not working 0 Answers