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 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.

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

How to rotate camera by GUI texture on android platform 1 Answer

Drawing UI text on GUI.DrawTexture , How to do it ? 1 Answer

Background hides text. How to solve that? -1 Answers


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