StellarXipher/Assets/Scripts/UsbInteractable.cs
zephyr-jchen 42dd1d02ba
Some checks failed
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Successful in 5m54s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Successful in 5m43s
Build project / Publish to itch.io (StandaloneLinux64) (push) Successful in 11s
Build project / Publish to itch.io (StandaloneWindows64) (push) Successful in 9s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (pull_request) Has been cancelled
Build project / Publish to itch.io (StandaloneLinux64) (pull_request) Has been cancelled
Build project / Publish to itch.io (StandaloneWindows64) (pull_request) Has been cancelled
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (pull_request) Has been cancelled
add usb for doors
2025-04-19 08:00:08 +08:00

48 lines
1.3 KiB
C#

using UnityEngine;
using TMPro;
public class UsbInteractable : MonoBehaviour
{
public GameObject interactionHintUI; // Reference to UI text
public Item itemToAddToInventory; // ScriptableObject item to add
private bool isMouseHovering = false;
void OnMouseEnter()
{
interactionHintUI.SetActive(true);
interactionHintUI.GetComponent<TextMeshProUGUI>().text =
$"Left-click to download {itemToAddToInventory.itemName} to tablet";
isMouseHovering = true;
Debug.Log($"Mouse entered USB for {itemToAddToInventory.itemName}. Showing hint.");
}
void OnMouseExit()
{
interactionHintUI.SetActive(false);
isMouseHovering = false;
Debug.Log($"Mouse exited USB for {itemToAddToInventory.itemName}. Hiding hint.");
}
void Update()
{
if (isMouseHovering && Input.GetMouseButtonDown(0))
{
Debug.Log($"Downloaded {itemToAddToInventory.itemName} to inventory.");
interactionHintUI.SetActive(false);
// Add to Inventory
var inventory = FindObjectOfType<Inventory>();
if (inventory != null)
{
inventory.AddItem(itemToAddToInventory);
}
// Hide USB object from scene
gameObject.SetActive(false);
}
}
}