- Home /
How to fix this Score UI problem
I am trying to make a currency system that can save all the points that the player earned and show it to the player through UI so i made these scripts:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro;
public class shop : MonoBehaviour { public TMPro.TextMeshProUGUI Pointtext; public float Points ;
  public void Start()
  {
     Points = PlayerPrefs.GetFloat("Points");
    
     Pointtext.text = "score : " + Points;
  }
 // Start is called before the first frame update
  
 // Update is called once per frame
 void Update()
 {
     
 }
 public void score()
 {
     
     
      Points +=  PlayerPrefs.GetFloat("Highscore");
    
 }
}
and then this script of highscore
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro;
public class PlayerHealth : MonoBehaviour {
 public GameObject death;
 public int maxHealth = 100;
 public static int currentHealth;
 public HealthBar healthBar;
 // Start is called before the first frame update
 void Start()
 {
     currentHealth = maxHealth;
     healthBar.SetMaxHealth(maxHealth);
 }
 // Update is called once per frame
 void Update()
 {
  
 }
 
   
 public void TakeDamage(int damage) 
 {
     currentHealth  -= damage;
 
     healthBar.SetHealth(currentHealth);
     if( currentHealth  <= 0)
     {
         Die();
     }
 }
 void Die ()
 {
    Destroy(gameObject);
    audioman.PlaySound ("explosion");
    Instantiate(death, transform.position, Quaternion.identity);
    PlayerPrefs.SetFloat ("Highscore", ScoreScript.scoreValue);
    
 }
   
} The problem that came to me is that the points are displaying itself in a different Ui and not in its supposed to. It is displaying and saving it self in scoreing Ui where game displays coins when player is earning them I want the points to be shown in Shop UI Please tell how to fix it. If you are curious about the scoring script I am giving that as well.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class ScoreScript : MonoBehaviour {
 public static int scoreValue = 0;
 public static Text Score;
 // Start is called before the first frame update
 void Start()
 {
     Score = GetComponent<Text> ();
     
 }
 // Update is called once per frame
 void Update()
 {
     Score.text = "Score: " + scoreValue;
 }
}
Pls Help me Thankyou,
did you try to convert int to text? you use .ToString() method for that.
Can you give me a example for that(using my script)
I did a little research and I think "Highscore" is the problem because it doesn't have value so I am trying to declare it's value in shop script so player health not used for this work.
Sorry for changing my decision quickly but it also came in my $$anonymous$$d that if I will declare the value in die method it will get the overall value that player collected.
Answer by logicandchaos · Jan 11, 2021 at 03:32 PM
Sounds like you refenced the wrong Text component. But what I would do rather than use playerprefs is put it all in a scriptable object. Then you can accesses anytime anywhere.
Answer by Ashmit2020 · Jan 12, 2021 at 02:16 AM
@logicandchaos can you give more details and examples(using m script) Please.
And actually, both of the text is in different scenes
Your answer
 
 
             Follow this Question
Related Questions
points system gets overrwriten 3 Answers
Object disappears on running 1 Answer
Player Prefs not saving 0 Answers
Creating multiple lines using multiple Line Renders, but all are receiving the same update. 1 Answer
Double Score Problem ? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                