Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Ashmit2020 · Jan 11, 2021 at 11:14 AM · script.unity 2dscore systempoints

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,

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AshwinTheGammer · Jan 11, 2021 at 12:17 PM 0
Share

did you try to convert int to text? you use .ToString() method for that.

avatar image Ashmit2020 AshwinTheGammer · Jan 11, 2021 at 02:49 PM 0
Share

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.

avatar image Ashmit2020 AshwinTheGammer · Jan 11, 2021 at 02:54 PM 0
Share

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.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

142 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges