- Home /
What's wrong code if-else with tag script ?
Hello I have the right panel and the wrong panel, the panel is used to check whether the object is dragging and dropping in the right slot. but in this code, when I run the wrong panel it always appears first, before I drag and drop the object. even though I have set it to be inactive. what should I fix ?
using UnityEngine; using System.Collections; using UnityEngine.EventSystems; using UnityEngine.SceneManagement;
public class CekBenar3 : MonoBehaviour
{
public float delay = 1;
[SerializeField]
private GameObject PanelBenar;
[SerializeField]
private GameObject PanelSalah;
void Start()
{
PanelBenar.SetActive(false);
PanelSalah.SetActive(false);
}
void Update()
{
if (Slot1.cek1 && Slot2.cek2 && Slot3.cek3)
{
GameObject objek1 = GameObject.FindGameObjectWithTag("Benar1");
GameObject objek2 = GameObject.FindGameObjectWithTag("Benar2");
GameObject objek3 = GameObject.FindGameObjectWithTag("Benar3");
if (objek1.transform.parent.tag == "Jawab1" && objek2.transform.parent.tag == "Jawab2" && objek3.transform.parent.tag == "Jawab3")
{
PanelBenar.SetActive(true);
}
else
{
PanelSalah.SetActive(true);
}
}
}
Comment