79 lines
1.3 KiB
C#
79 lines
1.3 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public class InteriorDoorOpen : MonoBehaviour
|
|
{
|
|
public float smooth = 1f;
|
|
|
|
private int hide = 1;
|
|
|
|
public int angle = 90;
|
|
|
|
public Camera cam;
|
|
|
|
public float RayDistance = 1.7f;
|
|
|
|
public float maxD = 1.7f;
|
|
|
|
private Ray ray;
|
|
|
|
private bool open;
|
|
|
|
public bool isopen;
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (!Input.GetKeyDown("f"))
|
|
{
|
|
return;
|
|
}
|
|
ray = cam.ScreenPointToRay(Input.mousePosition);
|
|
if (Physics.Raycast(ray, out var hitInfo, RayDistance) && hitInfo.transform.tag == "Door" && Vector3.Distance(hitInfo.transform.position, base.transform.position) < maxD && !isopen)
|
|
{
|
|
open = !open;
|
|
if (open)
|
|
{
|
|
StartCoroutine("one");
|
|
}
|
|
else
|
|
{
|
|
StartCoroutine("two");
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerator one()
|
|
{
|
|
if (!isopen)
|
|
{
|
|
while (hide < angle)
|
|
{
|
|
base.transform.rotation *= Quaternion.Euler(0f, 0f - smooth, 0f);
|
|
hide++;
|
|
isopen = true;
|
|
yield return null;
|
|
}
|
|
}
|
|
isopen = false;
|
|
hide = 1;
|
|
yield return null;
|
|
}
|
|
|
|
private IEnumerator two()
|
|
{
|
|
if (!isopen)
|
|
{
|
|
while (hide < angle)
|
|
{
|
|
base.transform.rotation *= Quaternion.Euler(0f, smooth, 0f);
|
|
hide++;
|
|
isopen = true;
|
|
yield return null;
|
|
}
|
|
}
|
|
isopen = false;
|
|
hide = 1;
|
|
yield return null;
|
|
}
|
|
}
|