All checks were successful
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Successful in 5m1s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Successful in 5m41s
Build project / Publish to itch.io (StandaloneLinux64) (push) Successful in 5s
Build project / Publish to itch.io (StandaloneWindows64) (push) Successful in 6s
93 lines
2.9 KiB
C#
93 lines
2.9 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
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;
|
|
|
|
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;
|
|
// mark key card as picked up
|
|
if (keyCardPlayer != null)
|
|
{
|
|
keyCardPlayer.hasKeyCard = true;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|