Hey folks,
I’m working on a mobile project that requires score to be collected from 3 score generating buttons. All three buttons have different point value assigned to them. I have:
Snow button for 25 points.
DJ button for 50 points.
SnS button for 100 points.
I need to collect the score on a central collector but I’m having an issue. When I press the same button multiple times the counter works fine but as soon as I hit one of the other buttons, the counter resets back to 0 before adding the points from that button on.
I’ve seen this problem solved when colliders and OnTriggerEnter are involved but I am quite new to this so I’m struggling to apply those tutorials to my buttons.
Heres my code that I adapted from a tutorial:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ButtonClickScriptSnow : MonoBehaviour
{
public Button button;
public Text text;
public int currentPoints =0;
public int currentScore;
public void ClickButton()
{
if (button != null)
{
currentScore = currentPoints + 25;
if (text != null)
{
text.text = "" + currentScore.ToString();
}
}
}
}
I change the point value and the name of the code for each button. Any help is appreciated, thanks.