Files
HauntedBloodlines/Assets/Scripts/WindowDebugging.cs
2025-05-29 22:31:40 +03:00

99 lines
2.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WindowDebugging : MonoBehaviour
{
[Header("Type of window")]
public bool WindowSmall;
[Header("Window state")]
public bool CanOpenWindow = true;
public bool WindowIsOpen;
[Header("Debugging variables")]
private bool IsInTrigger;
public float _LerpTime = 0f;
public float _OpenPosition = 0.5f;
public float _ClosedPosition = 0.0f;
private float _OpenPositionWindowShort = 0.38f;
Vector3 _OpenPos;
Vector3 _ClosedPos;
// Start is called before the first frame update
void Start()
{
if (WindowSmall)
{
_OpenPosition = _OpenPositionWindowShort;
}
if (WindowIsOpen)
{
transform.localPosition = new Vector3(0f, _OpenPosition, 0f);
}
_OpenPos = new Vector3(0f, _OpenPosition, 0f);
_ClosedPos = new Vector3(0f, _ClosedPosition, 0f);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0) && IsInTrigger)
{
if (!WindowIsOpen)
{
StopAllCoroutines();
_LerpTime = 0f;
StartCoroutine(OpenWindow());
}
else
{
StopAllCoroutines();
_LerpTime = 0f;
StartCoroutine(CloseWindow());
}
}
}
private void OnTriggerStay(Collider col)
{
if(col.gameObject.tag == "Player")
{
IsInTrigger = true;
}
}
private void OnTriggerExit(Collider col)
{
IsInTrigger = false;
}
public IEnumerator OpenWindow()
{
while(_LerpTime <= 1f)
{
transform.localPosition = Vector3.Lerp(transform.localPosition, _OpenPos, _LerpTime);
_LerpTime += 0.8f * Time.deltaTime;
WindowIsOpen = true;
print("Is opening window");
yield return null;
}
}
public IEnumerator CloseWindow()
{
while (_LerpTime <= 1f)
{
transform.localPosition = Vector3.Lerp(transform.localPosition, _ClosedPos, _LerpTime);
_LerpTime += 0.8f * Time.deltaTime;
WindowIsOpen = false;
print("Is closing window");
yield return null;
}
}
}