Files
SimUL/Assets/Brick Project Studio/Apartment Kit/Common/Scripts & Animation/Closet/ClosetopencloseDoor.cs
T
Vladimir Koshevarov 6388763d98 Added new assets
2023-02-20 19:02:00 +02:00

72 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace SojaExiles
{
public class ClosetopencloseDoor : MonoBehaviour
{
public Animator Closetopenandclose;
public bool open;
public Transform Player;
void Start()
{
open = false;
}
void OnMouseOver()
{
{
if (Player)
{
float dist = Vector3.Distance(Player.position, transform.position);
if (dist < 15)
{
if (open == false)
{
if (Input.GetMouseButtonDown(0))
{
StartCoroutine(opening());
}
}
else
{
if (open == true)
{
if (Input.GetMouseButtonDown(0))
{
StartCoroutine(closing());
}
}
}
}
}
}
}
IEnumerator opening()
{
print("you are opening the door");
Closetopenandclose.Play("ClosetOpening");
open = true;
yield return new WaitForSeconds(.5f);
}
IEnumerator closing()
{
print("you are closing the door");
Closetopenandclose.Play("ClosetClosing");
open = false;
yield return new WaitForSeconds(.5f);
}
}
}