using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraRaycast : MonoBehaviour
{
public Camera cam;
void Start()
{
}
void Update()
{
Ray ray = cam.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 1000))
if (hit.transform.tag == "Interactable")
{
print("I'm looking at " + hit.transform.name);
}
else
print("I'm looking at nothing!");
}
}
This is working fine but this send raycast hit from the camera. I want to send the raycast from the mouse cursor so if the mouse cursor is moving over object it will detect it. Just instead the camera the mouse cursor.