74 lines
1.8 KiB
C#
74 lines
1.8 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
using System.Collections;
|
|
|
|
|
|
public class AmbilBarang : MonoBehaviour
|
|
{
|
|
public Transform kameraPlayer;
|
|
public float radiusAmbil = 1f;
|
|
public LayerMask layerItem;
|
|
|
|
public GameObject uiListBarang;
|
|
public GameObject canvasUtama;
|
|
public StartGempa pemicuGempa;
|
|
|
|
private int totalBarang;
|
|
private int barangTersisa;
|
|
|
|
void Start()
|
|
{
|
|
totalBarang = 0;
|
|
foreach (Transform child in uiListBarang.transform)
|
|
{
|
|
if (child.GetComponent<TextMeshProUGUI>())
|
|
{
|
|
totalBarang++;
|
|
}
|
|
}
|
|
|
|
barangTersisa = totalBarang;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.JoystickButton0) || Input.GetKeyDown(KeyCode.L))
|
|
{
|
|
Collider[] hitItems = Physics.OverlapSphere(kameraPlayer.position, radiusAmbil, layerItem);
|
|
foreach (var hit in hitItems)
|
|
{
|
|
string tagBarang = hit.gameObject.tag;
|
|
Destroy(hit.gameObject);
|
|
HilangkanDariUI(tagBarang);
|
|
}
|
|
}
|
|
}
|
|
|
|
void HilangkanDariUI(string tagBarang)
|
|
{
|
|
foreach (Transform child in uiListBarang.transform)
|
|
{
|
|
if (child.GetComponent<TextMeshProUGUI>() && child.name.ToLower().Contains(tagBarang.ToLower()))
|
|
{
|
|
child.gameObject.SetActive(false);
|
|
barangTersisa--;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (barangTersisa <= 0)
|
|
{
|
|
canvasUtama.SetActive(false);
|
|
pemicuGempa.SiapkanGempa();
|
|
StartCoroutine(MulaiGempaDenganDelay());
|
|
}
|
|
|
|
IEnumerator MulaiGempaDenganDelay()
|
|
{
|
|
yield return new WaitForSeconds(3f);
|
|
pemicuGempa.MulaiGempa();
|
|
}
|
|
|
|
}
|
|
}
|