Point Counter Works Only Once!

Hello guys. I pretty much have many canvas in my scene. What I want is when a canvas is enabled to add 1 point. Here is the script:

     using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     using UnityEngine.UI;
     
     
     public class test2 : MonoBehaviour 
    {
     
         public Text scoreText;
         public int point;
		 private bool shouldScore = true;
		 
		 void OnEnable () 
		{
		 
		     if (this.shouldScore && gameObject.activeSelf)
		    {
		 
		         point++;
		         scoreText.text = point + "";
		         
		         shouldScore = false;
	  		}
	    }
    }

So it works only for the 1st canvas. One guy told me to modify shouldScore = false;
but i can not figure it out… any thoughts?

Good day.

So many “strange” things. You are little lost. I supose this script is attached to the canvas itself.

first, in the method OnEnable, is unnessary use the condition gameObject.activeSelf, because this methid is runned the first frame the object becomes active, so always will be true.

Second, use this.shouldScore is the same as shouldScore , its a private variable, only exists in this script. in this gameobject, so the comand this is implicit.

Then.

If this script is in every canvas, every canvas is storing only its own puntuation. Each canvas, when open change its poit value from 0 to 1 , thats all.

You need a general script to store the puntuation, and each canvas script must change the value of points from this general script, not from its own.

If you dont know how to do this, you need to learn basic code about reference other scripts. is 100% basic if you want to continue developing.

Good luck!
Bye!