mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 04:42:13 +01:00
62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class HomeSceneBtnBigScript : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
|
{
|
|
[SerializeField] GameObject background;
|
|
[SerializeField] float hoverTransitionTime = 0.1f;
|
|
[SerializeField] float exitTransitionTime = 0.1f;
|
|
[SerializeField] Color backgroundColor;
|
|
|
|
float hoveringTimePassed = 0.0f;
|
|
float exitingTimePassed = 0.0f;
|
|
|
|
bool isHovering = false;
|
|
|
|
void Update()
|
|
{
|
|
RectTransform rectTransform = GetComponent<RectTransform>();
|
|
RectTransform backgroundRectTranform = background.GetComponent<RectTransform>();
|
|
|
|
background.GetComponent<Image>().color = backgroundColor;
|
|
|
|
if (isHovering)
|
|
{
|
|
exitingTimePassed = 0.0f;
|
|
hoveringTimePassed += Time.deltaTime;
|
|
|
|
|
|
backgroundRectTranform.sizeDelta = new Vector2(Mathf.Lerp(0, rectTransform.rect.width, hoveringTimePassed / hoverTransitionTime), rectTransform.rect.height);
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
hoveringTimePassed = 0.0f;
|
|
exitingTimePassed += Time.deltaTime;
|
|
|
|
backgroundRectTranform.sizeDelta = new Vector2(Mathf.Lerp(rectTransform.rect.width, 0, exitingTimePassed / exitTransitionTime), rectTransform.rect.height);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
isHovering = true;
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
isHovering = false;
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
isHovering = false;
|
|
}
|
|
}
|