59 lines
1.3 KiB
C#
59 lines
1.3 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class ItemSelector : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField]
|
||
|
private Camera cam;
|
||
|
private InteractableItem selected;
|
||
|
[SerializeField]
|
||
|
private bool debug = false;
|
||
|
[SerializeField]
|
||
|
private LayerMask mask;
|
||
|
public static ItemSelector instance;
|
||
|
[SerializeField]
|
||
|
private float range = 1;
|
||
|
|
||
|
public InteractableItem Selected { get { return selected; } }
|
||
|
|
||
|
// Start is called before the first frame update
|
||
|
void Start()
|
||
|
{
|
||
|
instance = this;
|
||
|
}
|
||
|
|
||
|
void FixedUpdate()
|
||
|
{
|
||
|
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
|
||
|
RaycastHit hit;
|
||
|
|
||
|
if (Physics.Raycast(ray, out hit,range,layerMask:mask))
|
||
|
{
|
||
|
if(selected!= null||hit.transform.gameObject==null)
|
||
|
{
|
||
|
selected.Disable();
|
||
|
}
|
||
|
|
||
|
selected = hit.transform.gameObject.GetComponent<InteractableItem>();
|
||
|
selected.Enable();
|
||
|
print(selected);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (selected != null)
|
||
|
{
|
||
|
selected.Disable();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|