What's wrong code if-else with tag script?












1














hirarkyHello 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 ?



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);
}
}
}
}









share|improve this question
























  • Can you add a screenshot of your game objects hierarchy?
    – Ivan Kaloyanov
    Nov 12 at 10:03










  • yes, this is the hierarchy screenshots file
    – Riska Anisah
    Nov 12 at 13:31










  • There is still not enough information. What is Slot1.cek1? What object is Benar1? What object is tagged Jawab1? My guess as to your problem is that you're trying to validate all 3 objects at the same time (you can't: only one is being dragged). I'm also pretty sure that the tag if-statement is always true (no code changes the tags here, and GameObject.Find presumably always returns the same object).
    – Draco18s
    Nov 12 at 16:42












  • Recommendation: don't code in Indian. Even if you do, don't expect people on SO to know Indian and be able to read your code.
    – Arshia001
    Nov 13 at 4:13










  • hello if I may ask again. I have a problem with if statment on onmousedown. they can't read which button 1.2 or 3 is clicked. how should I handle it, please help me public GameObject karakter; public GameObject ButtonLevel1; public GameObject ButtonLevel2; private void OnMouseDown() { if (ButtonLevel1) { Debug.Log("a"); } if (ButtonLevel2) { Debug.Log("b"); }}
    – Riska Anisah
    Nov 14 at 22:25


















1














hirarkyHello 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 ?



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);
}
}
}
}









share|improve this question
























  • Can you add a screenshot of your game objects hierarchy?
    – Ivan Kaloyanov
    Nov 12 at 10:03










  • yes, this is the hierarchy screenshots file
    – Riska Anisah
    Nov 12 at 13:31










  • There is still not enough information. What is Slot1.cek1? What object is Benar1? What object is tagged Jawab1? My guess as to your problem is that you're trying to validate all 3 objects at the same time (you can't: only one is being dragged). I'm also pretty sure that the tag if-statement is always true (no code changes the tags here, and GameObject.Find presumably always returns the same object).
    – Draco18s
    Nov 12 at 16:42












  • Recommendation: don't code in Indian. Even if you do, don't expect people on SO to know Indian and be able to read your code.
    – Arshia001
    Nov 13 at 4:13










  • hello if I may ask again. I have a problem with if statment on onmousedown. they can't read which button 1.2 or 3 is clicked. how should I handle it, please help me public GameObject karakter; public GameObject ButtonLevel1; public GameObject ButtonLevel2; private void OnMouseDown() { if (ButtonLevel1) { Debug.Log("a"); } if (ButtonLevel2) { Debug.Log("b"); }}
    – Riska Anisah
    Nov 14 at 22:25
















1












1








1







hirarkyHello 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 ?



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);
}
}
}
}









share|improve this question















hirarkyHello 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 ?



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);
}
}
}
}






if-statement unity3d tags






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 13:29

























asked Nov 12 at 0:44









Riska Anisah

43




43












  • Can you add a screenshot of your game objects hierarchy?
    – Ivan Kaloyanov
    Nov 12 at 10:03










  • yes, this is the hierarchy screenshots file
    – Riska Anisah
    Nov 12 at 13:31










  • There is still not enough information. What is Slot1.cek1? What object is Benar1? What object is tagged Jawab1? My guess as to your problem is that you're trying to validate all 3 objects at the same time (you can't: only one is being dragged). I'm also pretty sure that the tag if-statement is always true (no code changes the tags here, and GameObject.Find presumably always returns the same object).
    – Draco18s
    Nov 12 at 16:42












  • Recommendation: don't code in Indian. Even if you do, don't expect people on SO to know Indian and be able to read your code.
    – Arshia001
    Nov 13 at 4:13










  • hello if I may ask again. I have a problem with if statment on onmousedown. they can't read which button 1.2 or 3 is clicked. how should I handle it, please help me public GameObject karakter; public GameObject ButtonLevel1; public GameObject ButtonLevel2; private void OnMouseDown() { if (ButtonLevel1) { Debug.Log("a"); } if (ButtonLevel2) { Debug.Log("b"); }}
    – Riska Anisah
    Nov 14 at 22:25




















  • Can you add a screenshot of your game objects hierarchy?
    – Ivan Kaloyanov
    Nov 12 at 10:03










  • yes, this is the hierarchy screenshots file
    – Riska Anisah
    Nov 12 at 13:31










  • There is still not enough information. What is Slot1.cek1? What object is Benar1? What object is tagged Jawab1? My guess as to your problem is that you're trying to validate all 3 objects at the same time (you can't: only one is being dragged). I'm also pretty sure that the tag if-statement is always true (no code changes the tags here, and GameObject.Find presumably always returns the same object).
    – Draco18s
    Nov 12 at 16:42












  • Recommendation: don't code in Indian. Even if you do, don't expect people on SO to know Indian and be able to read your code.
    – Arshia001
    Nov 13 at 4:13










  • hello if I may ask again. I have a problem with if statment on onmousedown. they can't read which button 1.2 or 3 is clicked. how should I handle it, please help me public GameObject karakter; public GameObject ButtonLevel1; public GameObject ButtonLevel2; private void OnMouseDown() { if (ButtonLevel1) { Debug.Log("a"); } if (ButtonLevel2) { Debug.Log("b"); }}
    – Riska Anisah
    Nov 14 at 22:25


















Can you add a screenshot of your game objects hierarchy?
– Ivan Kaloyanov
Nov 12 at 10:03




Can you add a screenshot of your game objects hierarchy?
– Ivan Kaloyanov
Nov 12 at 10:03












yes, this is the hierarchy screenshots file
– Riska Anisah
Nov 12 at 13:31




yes, this is the hierarchy screenshots file
– Riska Anisah
Nov 12 at 13:31












There is still not enough information. What is Slot1.cek1? What object is Benar1? What object is tagged Jawab1? My guess as to your problem is that you're trying to validate all 3 objects at the same time (you can't: only one is being dragged). I'm also pretty sure that the tag if-statement is always true (no code changes the tags here, and GameObject.Find presumably always returns the same object).
– Draco18s
Nov 12 at 16:42






There is still not enough information. What is Slot1.cek1? What object is Benar1? What object is tagged Jawab1? My guess as to your problem is that you're trying to validate all 3 objects at the same time (you can't: only one is being dragged). I'm also pretty sure that the tag if-statement is always true (no code changes the tags here, and GameObject.Find presumably always returns the same object).
– Draco18s
Nov 12 at 16:42














Recommendation: don't code in Indian. Even if you do, don't expect people on SO to know Indian and be able to read your code.
– Arshia001
Nov 13 at 4:13




Recommendation: don't code in Indian. Even if you do, don't expect people on SO to know Indian and be able to read your code.
– Arshia001
Nov 13 at 4:13












hello if I may ask again. I have a problem with if statment on onmousedown. they can't read which button 1.2 or 3 is clicked. how should I handle it, please help me public GameObject karakter; public GameObject ButtonLevel1; public GameObject ButtonLevel2; private void OnMouseDown() { if (ButtonLevel1) { Debug.Log("a"); } if (ButtonLevel2) { Debug.Log("b"); }}
– Riska Anisah
Nov 14 at 22:25






hello if I may ask again. I have a problem with if statment on onmousedown. they can't read which button 1.2 or 3 is clicked. how should I handle it, please help me public GameObject karakter; public GameObject ButtonLevel1; public GameObject ButtonLevel2; private void OnMouseDown() { if (ButtonLevel1) { Debug.Log("a"); } if (ButtonLevel2) { Debug.Log("b"); }}
– Riska Anisah
Nov 14 at 22:25



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254712%2fwhats-wrong-code-if-else-with-tag-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254712%2fwhats-wrong-code-if-else-with-tag-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini