Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Having a hard time with Highscore script

Discussion in 'Scripting' started by kriktsgrdn4evr, Dec 31, 2019.

  1. kriktsgrdn4evr

    kriktsgrdn4evr

    Joined:
    Dec 5, 2019
    Posts:
    12


    I watched and followed this whole thing and thus am making my first game. In the process of it, I've found however that I am having a hard time taking my score script which follows the players position on the map, and creating a high score out of it. I don't know what variables to use to convert it

    Player Score Code:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3.  
    4. public class Score : MonoBehaviour
    5. {
    6.  
    7.     public Transform player;
    8.     public Text scoreboard;
    9.    
    10.  
    11.     // Update is called once per frame
    12.     void Update()
    13.     {
    14.         scoreboard.text = player.position.z.ToString("0");
    15.         scoreboard.text = highscore.toString();
    16.  
    17.     }
    18. }

    Highscore Code:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3.  
    4. public class highscore : MonoBehaviour
    5. {
    6.     public Transform player;
    7.     private Text score;
    8.     bool scorecounter = false;  
    9.     public Text highScoreText;
    10.     int highScore;
    11.  
    12.     public void ScoreManager()
    13.     {
    14.         if (scorecounter == false)
    15.         {
    16.             scorecounter = true;
    17.            
    18.         }
    19.     }
    20.  
    21.     void Update()
    22.     {
    23.         highScore = (int)score;
    24.  
    25.  
    26.         if (PlayerPrefs.GetInt("score")<=highScoreText)
    27.         PlayerPrefs.SetInt("score", highScoreText);
    28.     }
    29.  
    30.  
    31. }
    I'm really at a loss and am pouring through different tutorials on youtube but nothing seems to be working. Halp!
     
  2. DaRealMik

    DaRealMik

    Joined:
    Jul 27, 2019
    Posts:
    69
    Try watching this. It worked for me.
     
  3. kriktsgrdn4evr

    kriktsgrdn4evr

    Joined:
    Dec 5, 2019
    Posts:
    12

    watched this and tried it. it's the basis of the high score code i have but it doesn't want to recognize me making the highscore into an int since the score itself is based off of the players position constantly updating. I'm at a loss on how to plug in the constant position tracking and somehow make that into a fixed score once you lose.
     
  4. yassinhakim700

    yassinhakim700

    Joined:
    Apr 19, 2020
    Posts:
    1
    im having the exact same problem i even watched the other video and still didnt know how to do it if u solved it by now can u pls send me the script?
     
  5. Albert13242

    Albert13242

    Joined:
    Feb 10, 2022
    Posts:
    1
    I'm having trouble to find a tutorial about highscore for a timer that doesn't only count seconds, but miliseconds and etz. to. Can you help me?
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,959
    What it counts is just presentation.

    Store time as a float and present it as an integer and you have seconds. Present it as a float and you have fractions of a second.

    Look up C# string formatting for more on how to present numbers with varying numbers of decimal places.

    And please don't necropost old threads. Start your own... it's FREE!