Screen Click -> Select GameObject
Unity3D Project / Scene Setting
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RayTest : MonoBehaviour
{
public GameObject targetObj = null;
public Camera cam = null;
public Transform point = null;
private void FixedUpdate()
{
if (Input.GetMouseButton(0) && cam != null)
{
RaycastHit hit;
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
point.position = hit.point;
Debug.DrawLine(cam.transform.position, hit.point, Color.yellow);
if (hit.transform.gameObject == targetObj)
{
Debug.Log("true");
}
}
}
}
}