multiply Score on Collision not working? check my code plz

So what I’m trying to do here is when the player collide By " x2" object the score gets update +2 instead of +1 , I tried a lot of codes and I can’t get anything to work, maybe its easy and I miss something, please check my code and guide me here

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class UIManager : MonoBehaviour{

public static bool  gameOver;

public Text scoreText;
 int score;

bool x2= false;

// Use this for initialization
void Start () {
	gameOver = false;
	score = 0;
	InvokeRepeating ("scoreUpdate", 1.0f, 0.5f);

}

// Update is called once per frame
void Update () {
scoreText.text = "Score: " + score;

}

public void scoreUpdate() {

	if (gameOver == false) {
		if (x2 == false) {
			score += 1;

		}
		if (x2 == true) {

			score += 2;

		}
	}
}

public void gameover(){

	gameOver = true;
	
}

void OnTriggerEnter2D (Collider2D col) {

	if (col.gameObject.tag == "x2") {

		Destroy (col.gameObject);

		x2 = true;

		float timer = 5.0f;

		timer -= Time.deltaTime;

		if (timer <= 0) {
			x2 = false;
		}
	}
}

}

the scores only update +1 and never multiply when collision is happens.

If your collider for the 2x object is a trigger, it might not work. Or maybe you didnt assign the tag, just created it. Or you have a typo in the tag’s name.

I haven’t been able to locate where your problem is, but I’m not sure what you’re trying to accomplish with this though… as far as I can tell this should really never do anything except if your frame is extremely slow. I’ll try and step my way through the code in my head here, but I didn’t see an issue. What I’d recommend YOU do though is put some Debug.Log outputs or something in your collision check though just to see if it’s reaching that code (i.e. a collision is detected - make sure one object has a rigidbody if using collision)

float timer = 5.0f;
         timer -= Time.deltaTime;
         if (timer <= 0) {
             x2 = false;
         }

Edit: yah I’ve looked through the logic, and I think it should work, I’d just highly recommend you put a Debug.Log right after where you set x2=true and see if that code is ever reached… if not, there’s your issue (most likely you’re doing something wrong with colliders).