using UnityEngine;
using System.Collections;
public class Door : MonoBehaviour
{
public bool open = false;
public float doorOpenAngle = 90f;
public float doorCloseAngle = 0f;
public float smooth = 2f;
public bool isLocked = false;
public AudioClip lockdoorsound;
private AudioSource source;
void start()
{
}
public void ChangeDoorState()
{
if (isLocked != true)
{
open = !open;
GetComponent<AudioSource>().Play();
}
else
{
PlayLockedDoorSound();
}
}
void PlayLockedDoorSound()
{
source.PlayOneShot(lockdoorsound);
}
void Update()
{
if (open)
{
Quaternion targetRotationOpen = Quaternion.Euler(0, doorOpenAngle, 0);
transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotationOpen, smooth * Time.deltaTime);
}
else
{
Quaternion targetRotationClose = Quaternion.Euler(0, doorCloseAngle, 0);
transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotationClose, smooth * Time.deltaTime);
}
}
}
[THIS IS THE LINK THAT I’VE BEEN FOLLOWED]