I want to detect hit with a gameObject when I click on it with my mouse,
I’m using raycast and C#
using UnityEngine;
using System.Collections;
class ButtonTest : MonoBehaviour
{
public Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
public void Update()
{
if (Input.GetButton("Fire1"))
{
if (Physics.Raycast(ray, 100))
print("Hit something");
}
}
}