Download Assets/Scripts/Interact/InteractionManager.cs from AliAch/my-unity-assets: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/datasets/AliAch/my-unity-assets/resolve/main/Assets/Scripts/Interact/InteractionManager.cs
- Command line
-
hf download hf://datasets/AliAch/my-unity-assets/Assets/Scripts/Interact/InteractionManager.cs
-
curl -L -o InteractionManager.cs https://huggingface.co/datasets/AliAch/my-unity-assets/resolve/main/Assets/Scripts/Interact/InteractionManager.cs
1.39 kB
| using System.Collections; | |
| using System.Collections.Generic; | |
| using System.Diagnostics; | |
| using UnityEngine; | |
| public class InteractionManager : MonoBehaviour | |
| { | |
| public static InteractionManager instance; | |
| public InteractionUI ui; | |
| public Camera playerCam; | |
| public float dist = 5; | |
| private void Awake() | |
| { | |
| instance = this; | |
| } | |
| public void ShowUI(IInteractable interactable) | |
| { | |
| ui.gameObject.SetActive(true); | |
| ui.setUI(interactable.GetSprite(),interactable.GetHandle()); | |
| } | |
| public void HideUI() | |
| { | |
| ui.gameObject.SetActive(false); | |
| } | |
| private void Update() | |
| { | |
| if(playerCam == default) | |
| { | |
| return; | |
| } | |
| // hide UI If we are holding an object | |
| if (PickUpScript.instance != null && PickUpScript.instance.heldObj != null) | |
| { | |
| HideUI(); | |
| return; | |
| } | |
| RaycastHit hit = default; | |
| if (Physics.Raycast(playerCam.transform.position, playerCam.transform.forward, out hit, dist)) | |
| { | |
| if(hit.transform.TryGetComponent(out IInteractable interactable)) | |
| { | |
| ShowUI(interactable); | |
| if (interactable.CanInteract()) | |
| { | |
| interactable.interact(); | |
| } | |
| return; | |
| } | |
| } | |
| HideUI(); | |
| } | |
| } | |