This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
station_obscurum_unity/Assets/Scripts/Interactable/ItemSelector.cs

59 lines
1.3 KiB
C#
Raw Normal View History

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()
{
}
}