81 lines
1.3 KiB
C#
81 lines
1.3 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public class SlideDoorOpen : MonoBehaviour
|
|
{
|
|
public Camera cam;
|
|
|
|
public float RayDistance = 1.7f;
|
|
|
|
public float maxD = 1.7f;
|
|
|
|
private Ray ray;
|
|
|
|
private bool open;
|
|
|
|
public int angle = 14;
|
|
|
|
private int hide = 1;
|
|
|
|
private bool isopen;
|
|
|
|
public float smooth = 0.1f;
|
|
|
|
public float delay = 0.03f;
|
|
|
|
private void Update()
|
|
{
|
|
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.position += new Vector3(0f - smooth, 0f, 0f);
|
|
hide++;
|
|
isopen = true;
|
|
yield return new WaitForSeconds(delay);
|
|
}
|
|
}
|
|
isopen = false;
|
|
hide = 1;
|
|
yield return null;
|
|
}
|
|
|
|
private IEnumerator two()
|
|
{
|
|
if (!isopen)
|
|
{
|
|
while (hide < angle)
|
|
{
|
|
base.transform.position += new Vector3(smooth, 0f, 0f);
|
|
hide++;
|
|
isopen = true;
|
|
yield return new WaitForSeconds(delay);
|
|
}
|
|
}
|
|
isopen = false;
|
|
hide = 1;
|
|
yield return null;
|
|
}
|
|
}
|