61 lines
1.6 KiB
C#
61 lines
1.6 KiB
C#
using UnityEngine;
|
|
|
|
public class TombolBerlindung : MonoBehaviour
|
|
{
|
|
public StartGempa pengaturGempa;
|
|
public Transform kameraPemain;
|
|
public GameObject lantaiBawahMeja;
|
|
public float waktuAktifkanLantai = 5f;
|
|
public GameObject uiBerlindung;
|
|
|
|
|
|
public Transform titikBerlindung; //titik tujuan berlindung
|
|
|
|
private bool sudahBerlindung = false;
|
|
|
|
void Update()
|
|
{
|
|
if (sudahBerlindung) return;
|
|
|
|
if (Input.GetKeyDown(KeyCode.B) || Input.GetKeyDown(KeyCode.JoystickButton3))
|
|
{
|
|
if (kameraPemain == null) return;
|
|
|
|
float jarak = Vector3.Distance(transform.position, kameraPemain.position);
|
|
if (jarak < 4f)
|
|
{
|
|
Debug.Log("Berlindung di bawah meja!");
|
|
|
|
if (lantaiBawahMeja != null)
|
|
{
|
|
lantaiBawahMeja.SetActive(false);
|
|
Debug.Log("Lantai bawah meja dinonaktifkan.");
|
|
}
|
|
|
|
if (pengaturGempa != null && titikBerlindung != null)
|
|
{
|
|
pengaturGempa.HentikanGempa();
|
|
pengaturGempa.TeleportKeBawahMeja(titikBerlindung);
|
|
}
|
|
|
|
gameObject.SetActive(false);
|
|
sudahBerlindung = true;
|
|
if (uiBerlindung != null)
|
|
uiBerlindung.SetActive(true);
|
|
|
|
|
|
Invoke("AktifkanLantai", waktuAktifkanLantai);
|
|
}
|
|
}
|
|
}
|
|
|
|
void AktifkanLantai()
|
|
{
|
|
if (lantaiBawahMeja != null)
|
|
{
|
|
lantaiBawahMeja.SetActive(true);
|
|
Debug.Log("Lantai bawah meja diaktifkan kembali.");
|
|
}
|
|
}
|
|
}
|