TO SQUASH: main menu progress.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class MenuButton : MonoBehaviour
|
||||
{
|
||||
public bool isButtonPressed = false;
|
||||
|
||||
public Animator keyAnimator;
|
||||
|
||||
private SpriteRenderer spriteRenderer;
|
||||
|
||||
private Collider2D boxCollider;
|
||||
|
||||
private static Color transparent = new Color(1f, 1f, 1f, 0f);
|
||||
|
||||
private static Color opaque = new Color(1f, 1f, 1f, 1f);
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
boxCollider = GetComponent<Collider2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Mouse.current.leftButton.wasPressedThisFrame)
|
||||
{
|
||||
Vector2 mousePosition = Mouse.current.position.ReadValue();
|
||||
Vector2 worldMousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
|
||||
|
||||
if (boxCollider.OverlapPoint(worldMousePosition))
|
||||
{
|
||||
isButtonPressed = true;
|
||||
keyAnimator.SetTrigger("buttonChanged");
|
||||
} else {
|
||||
isButtonPressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isButtonPressed)
|
||||
{
|
||||
spriteRenderer.color = opaque;
|
||||
}
|
||||
else
|
||||
{
|
||||
spriteRenderer.color = transparent;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user