42 lines
988 B
C#
42 lines
988 B
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Prefab
|
|
{
|
|
// [RequireComponent(typeof(CircleCollider2D))]
|
|
public class HoverButtonPrefab : MonoBehaviour
|
|
{
|
|
public TMP_Text text;
|
|
public Button button;
|
|
// public CircleCollider2D circleCollider;
|
|
|
|
public float startRadius = 250;
|
|
public float endRadius = 100;
|
|
|
|
|
|
private void Start()
|
|
{
|
|
// circleCollider.radius=startRadius;
|
|
}
|
|
|
|
public void OnMouseOver()
|
|
{
|
|
var dir = (Input.mousePosition - transform.position).magnitude;
|
|
|
|
var color = button.image.color;
|
|
color.a = Mathf.Min((startRadius - dir) / (startRadius - endRadius), 1);
|
|
button.image.color = color;
|
|
}
|
|
|
|
public void OnMouseEnter()
|
|
{
|
|
button.gameObject.SetActive(true);
|
|
}
|
|
|
|
public void OnMouseExit()
|
|
{
|
|
button.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
} |