CypernBuilding/Assets/BNG Framework/Scripts/UI/VRKeyboardKeyCollider.cs

55 lines
1.6 KiB
C#
Raw Permalink Normal View History

2023-10-26 10:33:05 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BNG {
public class VRKeyboardKeyCollider : MonoBehaviour {
public float PressedInZValue = 0.01f;
public float PressInSpeed = 15f;
UnityEngine.UI.Button uiButton;
int itemsInTrigger = 0;
bool wasSelected = false;
void Awake() {
uiButton = GetComponentInParent<UnityEngine.UI.Button>();
}
void Update() {
if (itemsInTrigger > 0) {
transform.parent.localPosition = Vector3.Lerp(transform.parent.localPosition, new Vector3(transform.parent.localPosition.x, transform.parent.localPosition.y, PressedInZValue), Time.deltaTime * PressInSpeed);
if(!wasSelected) {
uiButton.onClick.Invoke();
// uiButton.Select();
wasSelected = true;
}
}
else {
transform.parent.localPosition = Vector3.Lerp(transform.parent.localPosition, new Vector3(transform.parent.localPosition.x, transform.parent.localPosition.y, 0), Time.deltaTime * PressInSpeed);
wasSelected = false;
}
}
void OnTriggerEnter(Collider other) {
//if (other.GetComponent<UITrigger>() != null || other.GetComponent<Grabber>() != null) {
if (other.GetComponent<UITrigger>() != null) {
itemsInTrigger++;
}
}
void OnTriggerExit(Collider other) {
if (other.GetComponent<UITrigger>() != null) {
itemsInTrigger--;
}
}
}
}