Abdul Mukheem Shaik 96dc2d1f98 3 scenes completed
2024-11-20 18:07:30 +01:00

71 lines
1.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using UnityEngine.UI;
public class Doors : MonoBehaviour
{
bool trig, open;//trig-проверка входа выхода в триггер(игрок должен быть с тегом Player) open-закрыть и открыть дверь
public float smooth = 2.0f;//скорость вращения
public float DoorOpenAngle = 85.0f;//угол вращения
private Vector3 defaulRot;
private Vector3 openRot;
public Text txt;//text
// Start is called before the first frame update
void Start()
{
defaulRot = transform.eulerAngles;
openRot = new Vector3(defaulRot.x, defaulRot.y + DoorOpenAngle, defaulRot.z);
}
// Update is called once per frame
void Update()
{
if (open)//открыть
{
transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, openRot, Time.deltaTime * smooth);
}
else//закрыть
{
transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, defaulRot, Time.deltaTime * smooth);
}
if (Input.GetKeyDown(KeyCode.E) && trig)
{
open = !open;
}
if (trig)
{
if (open)
{
txt.text = "Close E";
}
else
{
txt.text = "Open E";
}
}
}
private void OnTriggerEnter(Collider coll)//вход и выход в\из триггера
{
if (coll.tag == "Player")
{
if (!open)
{
txt.text = "Close E ";
}
else
{
txt.text = "Open E";
}
trig = true;
}
}
private void OnTriggerExit(Collider coll)//вход и выход в\из триггера
{
if (coll.tag == "Player")
{
txt.text = " ";
trig = false;
}
}
}