Search Unity

Cant post score leaderboard...

Discussion in 'Unity Ads & User Acquisition' started by oguzhan123, Mar 16, 2018.

  1. oguzhan123

    oguzhan123

    Joined:
    Feb 6, 2018
    Posts:
    3
    I have a simple code but code cant post score to leaderboard. I think it has an easy answer but I cant find? Can somebody help me please? thanks

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using GooglePlayGames;
    using UnityEngine.SocialPlatforms;
    public class Meter : MonoBehaviour
    {
    public GameObject player;
    public static Meter instance;
    Text texta;
    float beginPos;
    float curPos;
    int score;
    int topscore;
    public int multiplier = 1;
    public Text highScore;
    private void Awake()
    {
    if (instance == null)
    {
    instance = this;
    }
    }
    // Use this for initialization
    void Start()
    {
    beginPos = player.transform.position.y;
    texta = GetComponent<Text>();
    highScore.text = PlayerPrefs.GetInt("HighScore", 1).ToString();
    int topscore = PlayerPrefs.GetInt("HighScore", 0);
    }
    // Update is called once per frame
    void Update()
    {
    curPos = player.transform.position.y - beginPos;
    // score = (int)(curPos * multiplier);
    score = Mathf.RoundToInt(curPos * multiplier);
    texta.text = 1 + score + "m";
    if (score > topscore)
    {
    topscore = score;
    highScore.text = score.ToString();
    Debug.Log(score);
    }
    }
    public void StoreScore()
    {
    Debug.Log("Score: " + score + " :: Top Score: " + topscore);
    if (score > topscore)
    {
    topscore = score;
    PlayerPrefs.SetInt("HighScore", score);
    PlayGames.instance.AddScoreToLeaderboard(leaderboardID, (long)score);

    }
    }
    }
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
    looks like you are not calling StoreScore() anywhere? Or is that called from UI button?
     
  3. oguzhan123

    oguzhan123

    Joined:
    Feb 6, 2018
    Posts:
    3
    I am calling when player is dead
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
    in the update you are already setting topscore to be score value,
    if (score > topscore)
    {
    topscore = score;

    so then in the StoreScore() it wont go inside that if to save playerprefs,
    as this line returns false
    if (score > topscore)