Accumulated Points

Can someone help me create a script for total points that will increment base on accumulated points for each round.

If you’re looking for someone who will write this for you, please try this on http://connect.unity.com/

If you’re looking for advice how to achieve, please, post what you have so far and whic part of your code you’re uncertain and/or buggy. We’re here to help, but you have to do the work. (If you post code, please, use CODE tags)

totalPoints += currPoints;

1 Like

This is my current script. Problem is it always has 0 as value.

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

public class PlayerPoints : MonoBehaviour
{
    public int playerPoints;
    public int addPoints;
    public Text points;

    void Start()
    {
        points = GetComponent<Text>();
        points.text = playerPoints.ToString();
    }
    void Update()
    {
        if (Score.scoreValue > PlayerPrefs.GetInt("HighScore", 0))
        {
            addPoints = Score.scoreValue - PlayerPrefs.GetInt("HighScore", 0);
            playerPoints += addPoints;
        }
        else
        {
            playerPoints = PlayerPrefs.GetInt("HighScore", 0);
        }
    }
}

I made the script below just to test and value is still 0.

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

public class PlayerPoints : MonoBehaviour
{
    public int playerPoints;
    public Text points;

    void Start()
    {
        points = GetComponent<Text>();
        points.text = playerPoints.ToString();
    }
    void Update()
    {
        playerPoints += Score.scoreValue;
    }
}

How are you debugging? I might suggest

Debug.Log("Score is " + Score.scoreValue.ToString();

I made the script below just to test and value is still 0.

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

public class PlayerPoints : MonoBehaviour
{
    public int playerPoints;
    public Text points;

    void Start()
    {
        points = GetComponent<Text>();
        points.text = playerPoints.ToString();
    }
    void Update()
    {
        playerPoints += Score.scoreValue;
    }
}

[/QUOTE]
If you mean that your text only shows 0 that is because you only set the text once in start when it 0.
If you like to see the playerPoints value in your text component you need to write the value every frame.

There is no debug.log statement that I can see, perhaps you copy and pasted the old version?

Thank you @JeffDUnity3D and @fffMalzbier . I actually fixed the issue by creating new variable that will hold ‘points’ and replicate the ‘score’ function. Not sure if that is the right way to do it but for now I’m happy that it works.