Why can't won't my if then statements work?

So this is my code, everyhitng works fine except that after the code executes the part of the “if then” statement it doesn’t finish, for example the sprite will change but the Boolean that goes with the sprites won’t change nor will the scorecard change. What could I be doing wrong?

UPDATE: The Scorecard changes now but not the Boolean so every Tille becomes a Tic still

UPDATE 2: It apprears the quaestion isn’t clear enough, despite referring to a different script the boolean “Turn1” is only being changed on the idvidual Tille. I am going to attempt to add a turn counter of sorts to the refered to script “bol”.

UPDATE 3: It works, I added this to the script “bol”

private void OnMouseDown()

{

    if(Turn == true)

    {

        Turn = false;

    }

    if(Turn == false)

    {

        Turn = true;

    }

and I replaced all instances of “Turn1” with “OSA.Turn”. I am someone unsure of any of this code is redundant and would be interested of anyone can tell me why this worked :D. Thank you to those who posted.

public class Tile : MonoBehaviour
{

    public Sprite Tille;
    public Sprite Tic;
    public Sprite Tac;
    public int Scorecard;
    public GameObject CodeHold;
    private Bol OSA;
    private bool Turn1;
    
	// Use this for initialization
	void Start ()
    {
        this.gameObject.GetComponent<SpriteRenderer>().sprite = Tille;
        OSA = CodeHold.GetComponent<Bol>();
        Turn1 = OSA.Turn;
        Debug.Log(Turn1);
        Debug.Log(Scorecard);
       
    }

    private void OnMouseDown()
    {
        if (Turn1 == true)
        {
            if (this.gameObject.GetComponent<SpriteRenderer>().sprite == Tille)
            {               
                this.gameObject.GetComponent<SpriteRenderer>().sprite = Tic;
                Turn1 = false;
                Scorecard = 1;
            }
        }

        else if (Turn1 == false)
        {
            if (this.gameObject.GetComponent<SpriteRenderer>().sprite == Tille)
            {                
                this.gameObject.GetComponent<SpriteRenderer>().sprite = Tac;
                Turn1 = true;
                Scorecard = -1;
            }
        }
    }
}

Hello,

  • In both if statements you tried to get “sprite == Tille”, is that right?
  • Because you changed the sprite to - Tic and Tac
  • Shouldn’t it look for the new sprites?

  • Delete the inside if line (sprite == Tille) and see if it works