evelynshilosky

SelectionManager - Part 3

Jun 2nd, 2024
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6.  
  7. public class SelectionManager : MonoBehaviour
  8. {
  9.  
  10.     public GameObject interaction_Info_UI;
  11.     Text interaction_text;
  12.  
  13.     private void Start()
  14.     {
  15.         interaction_text = interaction_Info_UI.GetComponent<Text>();
  16.     }
  17.  
  18.     void Update()
  19.     {
  20.         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  21.         RaycastHit hit;
  22.         if (Physics.Raycast(ray, out hit))
  23.         {
  24.             var selectionTransform = hit.transform;
  25.  
  26.             if (selectionTransform.GetComponent<InteractableObject>())
  27.             {
  28.                 interaction_text.text = selectionTransform.GetComponent<InteractableObject>().GetItemName();
  29.                 interaction_Info_UI.SetActive(true);
  30.             }
  31.             else
  32.             {
  33.                 interaction_Info_UI.SetActive(false);
  34.             }
  35.  
  36.         }
  37.     }
  38. }
Add Comment
Please, Sign In to add comment