Question by
MontyMomentum · Jun 23, 2020 at 04:01 PM ·
booleanif statementinteger
If statement automatically true
In this script the If statement automatically becomes True even though the condition is not met. Here's my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Goal : MonoBehaviour
{
public Animator anim;
private static int scoreCoin;
public int aantCoin;
// Start is called before the first frame updateS
void Start()
{
anim.SetBool("Goal", false);
}
// Update is called once per frame
void Update()
{
scoreCoin = Collector.score;
if (aantCoin == scoreCoin);
{
anim.SetBool("Goal", true);
Debug.Log(aantCoin);
}
}
}
Comment
please change the Debug.Log(aantCoin);
to Debug.Log(aantCoin + " // scoreCoin: " + scoreCoin);
and confirm that your statement is correct.
It's showing aantCoin as 4 and scoreCoin as 0.
Best Answer
Answer by Captain_Pineapple · Jun 23, 2020 at 06:38 PM
ah yes, intresting issue. In line 20 behind your if statement there is a ;
which should not be there. that will basically terminate your if statement and the code is then just handled as if there was no if statement.
I consider this question to be answered and will accept this answer. I also move the question into the help room since this is just a trivial debugging question.