• 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 vivek · Mar 02, 2012 at 05:26 AM · score

How do I add score in my scene using GUIText?

I know this is a basic question and I apologize for that as well since I am new to Unity. I searched all the way out but ended up in vain while searching for score keeping, though I got few solutions here on this community while searching I am very much unclear on to how does adding score work and could it be saved while i am loading into the next scene.

Anybody could help solving the issue or provide some links/tutorials so that I would come to know better and clear regarding this would be great..

Thanks for your time.

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 Kleptomaniac · Mar 02, 2012 at 06:06 AM 0
Share

Could we see what code you've already got? Would really help in answering.

avatar image syclamoth · Mar 02, 2012 at 06:14 AM 0
Share

It's honestly pretty straightforward. $$anonymous$$ake a public GUIText reference in your script, and then update its text value in Update.

avatar image himanshu619 · Dec 15, 2012 at 09:41 PM 0
Share

Please check the new answer form me!

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Berenger · Mar 04, 2012 at 12:44 AM

To add at what syclamoth said, you'll need a static var to keep it through 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
avatar image
0

Answer by fjcym · Mar 28, 2012 at 06:27 AM

I have a similar Problem. I have a script but it doesn't have a text to count the score. Here's the script:

var PlayerScore = 0; var ScoreText = "Score: 0"; var MaxPoints : int;

function OnTriggerEnter( other : Collider ){ Debug.Log("OnTriggerEnter() was called"); if (other.tag == "point"){ Debug.Log("Other object is a point"); PlayerScore += 1; ScoreText = "Score: " + PlayerScore; Debug.Log("Score is now " + PlayerScore); Destroy(other.gameObject); } }

function Update(){ if(PlayerScore > MaxPoints){ PlayerScore = 16; print("You Win!"); ScoreText = "Score: 0"; } } If you could help it would be great. Hopefully this can help you to vivek.

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
0

Answer by himanshu619 · Dec 15, 2012 at 09:40 PM

Hey All, here is your answer: Note please put this script onto your "Player" only: var score = 0; var scoreText = "Score: 0"; var mySkin : GUISkin;

function OnTriggerEnter(other : Collider ) {

if (other.tag == "Pickup") { //Pickup is the tag please replace it with your pick-able item tag

     Debug.Log("Other object is a coin");

     score += 1;         //You can replace 1 with any integer this is you score 

     scoreText = "Score: " + score;

     Debug.Log("Score is now " + score);

     Destroy(other.gameObject);

 }

}

function OnGUI () {

 GUI.skin = mySkin;

 GUI.Label (Rect (200, 10, 200, 400), scoreText.ToString()); 

}

Note:Mark this answer as correct, Thank you.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

A node in a childnode? 1 Answer

How would I make a score board or how many enemies I killed? 1 Answer

Make a custom score counter in unity with c# 1 Answer

Unity and Facebook SDK managing Score System 1 Answer

High Score not retrieving 2 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