I am working on a game that will count the total number of ball hit to 10 different blocks. Having 5 pairs of blocks. A pair of blocks having different color that represents different score value. This color represent different point. I can see the counter of Score Increase from Inspector Tag on each blocks but couldn’t find a way to call each blocks and add them together before showing up in UI.
Making the blocks call a central scoring script when points are scored is probaly the easiest way to do this. Have a public function a empty object (or on your player or whatever is currently doing the scoring) that the function on the blocks can call.
In the scoring script:
public void AddScore(int scoreToAdd)
{
score += scoreToAdd;
//Also update you score text here
}
In the block script:
public GameObject scorer; /*or player or whatever you want, assign this in the editor*/
public int score /*the score for this block, also set in the editor*/
//call this function when you want to add score
player.GetComponent<insertNameOfScoringScriptHere>().AddScore(score);
Thanks for the update. i tried it and it works for individual blocks that will shown on Inspector under Increase Score. I added the code to TargetHit.cs script that holds the scoring function and OnTriggerEnter collider and is attached to every single blocks. While the Player.cs holds the ThrowBall() function, void Start and Fixed Update, and added the IncreaseScore() function that attached to MainCamera.
There is not Block script. Only TargetHit, Player, Singleton, GameManager and UpdateUI scripts.
I can see the individual blocks’ increase of score during play from the Inspector/Increase Score.
I attached the current photos for my next question to eliminate more lines of summary.
Heirarchy Tab
Inspector Tab
Each wall correspond to equivalent number like GreenZone is equal to 100 points, YellowZone is 50 points and RedZone is zero. I tried switch function inside OnTriggerEnter and uses each zone to identify each case and created individual function for each zone and no effect on the increase.
Pardon me if my question is not clear as I am quite confuse on what to ask.
How can I increase each individual blocks according to its assigned points once hit by the Player?
How will I be able to pint it in UpdateUI to appear in Canvas?