116 lines
2.5 KiB
C#
116 lines
2.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Events;
|
|
using TMPro;
|
|
public class ObjDrag : MonoBehaviour
|
|
{
|
|
|
|
[HideInInspector]public Vector2 SavePosisi;
|
|
[HideInInspector]public bool IsDiatasObj;
|
|
|
|
Transform SaveObj;
|
|
|
|
public int ID;
|
|
public TextMeshProUGUI Teks;
|
|
|
|
[Space]
|
|
|
|
public UnityEvent OnDragBenar;
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
SavePosisi = transform.position;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
private void OnMouseDown()
|
|
{
|
|
KumpulanSuara.instance.Panggil_Sfx(0);
|
|
}
|
|
|
|
private void OnMouseUp()
|
|
{
|
|
//transform.position = SavePosisi;
|
|
if (IsDiatasObj)
|
|
{
|
|
int ID_TempatDrop = SaveObj.GetComponent<TempatDrob>().ID;
|
|
|
|
if(ID == ID_TempatDrop)
|
|
{
|
|
transform.SetParent(SaveObj);
|
|
transform.localPosition = Vector3.zero;
|
|
transform.localScale = new Vector2(1.07f,1.02f);
|
|
SaveObj.GetComponent<SpriteRenderer>().enabled = false;
|
|
SaveObj.GetComponent<Rigidbody2D>().simulated = false;
|
|
SaveObj.GetComponent<BoxCollider2D>().enabled = false;
|
|
|
|
gameObject.GetComponent<BoxCollider2D>().enabled = false;
|
|
|
|
OnDragBenar.Invoke();
|
|
|
|
//ini jika sukses
|
|
GameSystem.instance.DataSaatIni++;
|
|
Data.DataScore += 10; //perhitungan skor
|
|
|
|
|
|
KumpulanSuara.instance.Panggil_Sfx(1);
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
transform.position = SavePosisi;
|
|
|
|
//jika salah
|
|
Data.DataNyawa--;
|
|
|
|
|
|
KumpulanSuara.instance.Panggil_Sfx(2);
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
transform.position = SavePosisi;
|
|
|
|
//jika tempat tidak ada
|
|
}
|
|
}
|
|
|
|
private void OnMouseDrag()
|
|
{
|
|
if (!GameSystem.instance.GameSelesai)
|
|
{
|
|
Vector2 Pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
|
transform.position = Pos;
|
|
}
|
|
|
|
}
|
|
|
|
private void OnTriggerStay2D(Collider2D trig)
|
|
{
|
|
if (trig.gameObject.CompareTag("Drop"))
|
|
{
|
|
IsDiatasObj = true;
|
|
SaveObj = trig.gameObject.transform;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void OnTriggerExit2D(Collider2D trig)
|
|
{
|
|
if (trig.gameObject.CompareTag("Drop"))
|
|
{
|
|
IsDiatasObj = false;
|
|
}
|
|
}
|
|
|
|
} |