I think i need some help. My score and highscore is fine, but when I’m pressing the button it doesn’t add score.
In my old ScoreManager script the “score” were an int, and now its a float. I think that the problem is there, but since I’m a noob at programming I’m not sure, and don’t know how to fix it.
Problem lies in the DestroyOnClick script down below.
ScoreManager code
public class ScoreManager1 : MonoBehaviour {
public Text scoreText;
public Text highScoreText;
public float scoreCount;
public float highScoreCount;
public float pointsPerSecond;
public bool scoreIncreasing;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (scoreIncreasing)
{
scoreCount += pointsPerSecond * Time.deltaTime;
}
if (scoreCount > highScoreCount)
{
highScoreCount = scoreCount;
}
scoreText.text = "Score: " + Mathf.Round(scoreCount);
highScoreText.text = "HighScore: " + Mathf.Round(highScoreCount);
}
}
Here is the DestroyOnClick script
public class DestroyOnClick : MonoBehaviour {
private float timer = 0;
public float X = 3;
public int scoreValue = 10;
public GameObject Button;
void Update()
{
timer += Time.deltaTime;
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 500.0f) && hit.transform.gameObject != null)
{
Destroy(hit.transform.gameObject);
ScoreManager1.scoreCount += scoreValue; //This is the problem
}
}
if (timer >= X) Destroy(Button);
}
}