50 lines
1.4 KiBLFS
C#
50 lines
1.4 KiBLFS
C#
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(Collider2D))]
|
|
|
|
public class Labeled : MonoBehaviour
|
|
{
|
|
[SerializeField] private string discoverText;
|
|
[SerializeField]
|
|
private FloatingLabelDirection discoverTextDirection = FloatingLabelDirection.Up;
|
|
[SerializeField] private float discoverTextOffset = 1;
|
|
[SerializeField] private float discoverXTextOffset = 0;
|
|
|
|
private FloatingLabel floatingLabel;
|
|
|
|
private Clickable? clickable;
|
|
|
|
private bool discovered => clickable?.discovered ?? true;
|
|
|
|
void Start()
|
|
{
|
|
clickable = GetComponent<Clickable>();
|
|
}
|
|
|
|
void OnMouseEnter()
|
|
{
|
|
if (!GameManager.singleton.CanPlay) return;
|
|
if ((discovered || GameManager.singleton.AllUnlocked) && discoverText != null && discoverText != "")
|
|
{
|
|
if (floatingLabel != null)
|
|
{
|
|
Destroy(floatingLabel.gameObject);
|
|
}
|
|
floatingLabel = Instantiate(GameManager.singleton.floatingLabelPrefab, transform.position + new Vector3(discoverXTextOffset, 0, 0), Quaternion.identity).GetComponent<FloatingLabel>();
|
|
|
|
floatingLabel.Spawn(discoverText, discoverTextDirection, discoverTextOffset);
|
|
}
|
|
|
|
GameManager.singleton.soundManager.PlayHoverSound();
|
|
}
|
|
|
|
void OnMouseExit()
|
|
{
|
|
if (!GameManager.singleton.CanPlay) return;
|
|
if (floatingLabel != null)
|
|
{
|
|
floatingLabel.Despawn();
|
|
}
|
|
}
|
|
}
|