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,