Hello everyone.
I want to implement the ability to select certain objects on the screen. So far I have a script that selects any object at all.
I wanted to check the selectable object by belonging to SerializeField, but did not figure out how.
How can this check be implemented or done otherwise?
using UnityEngine;
using UnityEngine.EventSystems;
public class SelectSphere : MonoBehaviour
{
[SerializeField] private Collider[] SelectList;
EventSystem SelectEventSystem;
void OnEnable()
{
SelectEventSystem = EventSystem.current;
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (UnityEngine.Physics.Raycast(ray, out hit))
{
if (hit.collider != null)
{
GameObject SelectedGameObject = hit.collider.gameObject;
SelectEventSystem.SetSelectedGameObject(SelectedGameObject);
Debug.Log("Selected : " + SelectEventSystem.currentSelectedGameObject);
}
}
}
}
}