Initial commit
This commit is contained in:
51
Assets/Scripts/BukaPintu1.cs
Normal file
51
Assets/Scripts/BukaPintu1.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class BukaPintu1 : MonoBehaviour
|
||||
{
|
||||
public Transform door;
|
||||
public float openAngle = 90f;
|
||||
public float closeAngle = 0f;
|
||||
public float smoothSpeed = 2f;
|
||||
private bool open = false;
|
||||
|
||||
public AudioSource audioSource;
|
||||
public AudioClip bukaPintuSound; // Suara pintu buka
|
||||
private bool soundPlayed = false; // Agar suara tidak berulang
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
Quaternion targetRotation = open ?
|
||||
Quaternion.Euler(0, openAngle, 0) :
|
||||
Quaternion.Euler(0, closeAngle, 0);
|
||||
|
||||
// Rotasi pintu
|
||||
door.localRotation = Quaternion.Slerp(door.localRotation, targetRotation, Time.deltaTime * smoothSpeed);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
open = true;
|
||||
}
|
||||
|
||||
if (!soundPlayed && audioSource != null && bukaPintuSound != null)
|
||||
{
|
||||
audioSource.PlayOneShot(bukaPintuSound);
|
||||
soundPlayed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
open = false;
|
||||
}
|
||||
|
||||
soundPlayed = false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user