Some checks failed
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Has been cancelled
Build project / Publish to itch.io (StandaloneLinux64) (push) Has been cancelled
Build project / Publish to itch.io (StandaloneWindows64) (push) Has been cancelled
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Has been cancelled
92 lines
3.0 KiB
C#
92 lines
3.0 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
|
|
public class PickUpKeyCard : MonoBehaviour
|
|
{
|
|
public TMP_Text interactionPrompt;
|
|
private Outline outline;
|
|
|
|
[SerializeField] private Animator objectAnimator;
|
|
[SerializeField] private string animationName = "PickupAnimation";
|
|
[SerializeField] private AudioClip pickupSound = null;
|
|
[SerializeField] private string keyCardName = "Deck D key card";
|
|
|
|
[SerializeField] private KeyCardPlayer keyCardPlayer = null;
|
|
[SerializeField] private float interactionDistance = 5.0f;
|
|
|
|
[SerializeField] private Item keyCardItem;
|
|
[SerializeField] private Inventory playerInventory;
|
|
|
|
private bool isPickedUp = false;
|
|
|
|
void Awake()
|
|
{
|
|
outline = GetComponent<Outline>();
|
|
if (outline != null)
|
|
outline.enabled = true;
|
|
|
|
if (interactionPrompt != null)
|
|
interactionPrompt.enabled = false;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (!isPickedUp)
|
|
{
|
|
Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
|
|
if (Physics.Raycast(ray, out RaycastHit hit, interactionDistance))
|
|
{
|
|
if (hit.collider.gameObject == gameObject)
|
|
{
|
|
if (interactionPrompt != null)
|
|
{
|
|
interactionPrompt.text = "Left click to pick up " + keyCardName;
|
|
interactionPrompt.enabled = true;
|
|
}
|
|
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
isPickedUp = true;
|
|
|
|
if (keyCardPlayer != null)
|
|
keyCardPlayer.hasKeyCard = true;
|
|
|
|
if (playerInventory != null && keyCardItem != null)
|
|
{
|
|
playerInventory.AddItem(keyCardItem);
|
|
|
|
InventoryUI inventoryUI = FindObjectOfType<InventoryUI>();
|
|
if (inventoryUI != null)
|
|
inventoryUI.RefreshUI();
|
|
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
if (outline != null)
|
|
outline.enabled = false;
|
|
|
|
if (interactionPrompt != null)
|
|
interactionPrompt.enabled = false;
|
|
|
|
if (objectAnimator != null)
|
|
objectAnimator.Play(animationName, 0, 0.0f);
|
|
|
|
if (pickupSound != null)
|
|
SoundFXManager.instance.PlaySound(pickupSound, transform, 1.5f);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (interactionPrompt != null)
|
|
interactionPrompt.enabled = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (interactionPrompt != null)
|
|
interactionPrompt.enabled = false;
|
|
}
|
|
}
|
|
}
|
|
}
|