• 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 aman_jha · Apr 26, 2014 at 08:15 PM · androidguitextureguitexthighscores

Making High Scores and scores via GUITexts

What's up Unitarians?

So I'm making this runner game, and I have a high score system - that should be working PERFECTLY, but it isn't. I have multiple GUITextures and GUITexts, and the score is raised by one every update, so your score can get pretty high. The code, named Entity, is pretty simple and self-explanatory. There are no errors in the console, so I have no idea what's happening.

 using UnityEngine;
 using System.Collections;
 
 public class Entity : MonoBehaviour {
 
     public float health;
     public GameObject ragdoll;
 
     //GUI Stuffs
     public GUITexture GameOverGUI;
     public GUITexture TryAgainGUI;
     public GUITexture YourScoreWasGUI;
     public GUIText ScoreGUIText;
     public GUITexture GameOverBackgroundGUI;
 
     //Score Stuffs
     public GUIText HighScore;
     public GUIText CurrentScore;
     private int highscore;
     private int score = 0;
 
     public void Start(){
         Instantiate(HighScore, new Vector3 (1.0f, 1.0f, 0f), Quaternion.identity);
         Instantiate(CurrentScore, new Vector3 (1.0f, 0.9f, 0f), Quaternion.identity);
 
         if (PlayerPrefs.GetInt("High Score Endless") == null){
             PlayerPrefs.SetInt("High Score Endless", 0);
         }
 
         highscore = PlayerPrefs.GetInt("High Score");
 
         HighScore.text = "Highscore: " + highscore;
     
     }
 
     public void Update(){
         //Score Holder
         score ++;
 
         CurrentScore.text = "Score: " + score;
 
         if (score > highscore){
             highscore = score;
             HighScore.text = "Highscore: " + highscore;
         }
     }
 
     public void TakeDamage(float dmg) {
         health -= dmg;
         
         if (health <= 0) {
             Die();    
         }
     }
     
     public void Die() {
         ToggleVisibility();    
 
         Destroy(this.gameObject);
 
         PlayerPrefs.SetInt("High Score Endless", highscore);
 
         ScoreGUIText.text = "" + score;
 
     }
 
     public void ToggleVisibility(){
 
         Instantiate(ScoreGUIText, new Vector3 (0.55f, 0.28f, 0f), Quaternion.identity);
         Instantiate(YourScoreWasGUI, new Vector3 (0.43f, 0.3f, 0f), Quaternion.identity);
         Instantiate(GameOverGUI, new Vector3 (0.5f, 0.65f, 0f), Quaternion.identity);
         Instantiate(TryAgainGUI, new Vector3 (0.5f, 0.425f, 0f), Quaternion.identity);
         Instantiate(GameOverBackgroundGUI, new Vector3 (0.5f, 0.5f, 0f), Quaternion.identity);
     }
 
 }
 
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 Burla · Apr 26, 2014 at 08:17 PM 0
Share

What exactly is the problem? Isn't the score showing?

avatar image aman_jha · Apr 26, 2014 at 08:32 PM 0
Share

Yeah - It just doesn't show up... I have no idea why.

avatar image Burla · Apr 26, 2014 at 08:35 PM 0
Share

Are the GUITexture and GUIText objects getting spawned in your game - can you see them in the Hierarchy?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by BlackHoleStorm · Apr 26, 2014 at 08:52 PM

You're trying to set your high score texts by just setting the int value, you need to add ToString to the end of it. For example

 public int val;
 public GUIText textToSet;
 
 void SetString()
 {
 textToSet.text = "The value is: " + val.ToString();
 }
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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

22 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

Related Questions

Android: How do you position GUITexture and GUIText according to different screen sizes (JS)? 2 Answers

GUITexture and GUIText on android 2 Answers

Replacing letters with images? 1 Answer

GUITexture touch play animation 0 Answers

GUI Text is small on some phones? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges