mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2026-07-31 07:29:02 +02:00
added layout for lobby scene
This commit is contained in:
59
Assets/Scripts/Lobby/LobbyBtn.cs
Normal file
59
Assets/Scripts/Lobby/LobbyBtn.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class LobbyBtn : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
||||
{
|
||||
[SerializeField] GameObject marker;
|
||||
|
||||
//Marker Lerp
|
||||
[SerializeField] float markerWidth = 40.0f;
|
||||
[SerializeField] float hoverMarkerTransitionTime = 0.1f;
|
||||
[SerializeField] float exitMarkerTransitionTime = 0.1f;
|
||||
|
||||
float hoveringTimePassed = 0.0f;
|
||||
float exitingTimePassed = 0.0f;
|
||||
|
||||
|
||||
bool isHovering = false;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isHovering)
|
||||
{
|
||||
exitingTimePassed = 0.0f;
|
||||
hoveringTimePassed += Time.deltaTime;
|
||||
|
||||
//Marker
|
||||
RectTransform rectTranform = marker.GetComponent<RectTransform>();
|
||||
rectTranform.sizeDelta = new Vector2(Mathf.Lerp(0, markerWidth, hoveringTimePassed / hoverMarkerTransitionTime), rectTranform.rect.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
hoveringTimePassed = 0.0f;
|
||||
exitingTimePassed += Time.deltaTime;
|
||||
|
||||
//Marker
|
||||
RectTransform rectTranform = marker.GetComponent<RectTransform>();
|
||||
rectTranform.sizeDelta = new Vector2(Mathf.Lerp(markerWidth, 0, exitingTimePassed / exitMarkerTransitionTime), rectTranform.rect.height);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
isHovering = true;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
isHovering = false;
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
isHovering = false;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lobby/LobbyBtn.cs.meta
Normal file
11
Assets/Scripts/Lobby/LobbyBtn.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42c07f2a233ce974b89bdbd702f9f8da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user