49 lines
1.4 KiBLFS
C#
49 lines
1.4 KiBLFS
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class Button : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
[SerializeField] private float scaleMultiplier = 1.1f;
|
|
|
|
[SerializeField] private bool bounceAnimation = false;
|
|
[SerializeField] private AnimationCurve bounceCurve;
|
|
[SerializeField] private float bounceDuration = 0.5f;
|
|
[SerializeField] private float bounceScale = 1f;
|
|
|
|
private bool hovering = false;
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
hovering = true;
|
|
transform.localScale *= scaleMultiplier;
|
|
CameraManager.singleton.ShowHoverTexture();
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
hovering = false;
|
|
transform.localScale = Vector3.one;
|
|
if (!CameraManager.singleton.isPlayingVideo)
|
|
CameraManager.singleton.ShowDefaultTexture();
|
|
else
|
|
Cursor.visible = false;
|
|
|
|
}
|
|
|
|
public void OnClick()
|
|
{
|
|
GameManager.singleton.soundManager.PlayClickSound();
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (bounceAnimation)
|
|
{
|
|
float mult = hovering ? 1 : 1 / scaleMultiplier;
|
|
transform.localPosition = new Vector3(-bounceCurve.Evaluate(Time.time % (bounceDuration * mult)) * bounceScale, transform.localPosition.y, transform.localPosition.z);
|
|
}
|
|
}
|
|
}
|