Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Spacetato · Nov 24, 2015 at 08:03 AM · scripting beginnerscorescore systemcounterscoring

How can I keep a score counter of how many points the player has collected on the screen?

I want "Score:" and then the score to increase with each collision/pickup of the object.

More specifically, I want "Score: " to become "Score: 1" after picking up a crystal shard, "Score: 2" after picking another, and etc every time the character picks up a crystal shard.

I'm quite new to scripting, and Javascript would be preferred, however C# is fine too.

Comment
Add comment · Show 1
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 ZefanS · Nov 24, 2015 at 08:59 AM 0
Share

It's usually best if you try to write the script yourself and then ask for help, rather than just asking someone to write it for you. That's the best way to learn after all. Anyhow, here's a general way to go about it:

  • Create a UI Canvas and add a Text object to it.

  • Write a script attached to the player that checks for collisions with the crystals

  • If a collision is detected, increment the score variable and then update the UI Text

Here are some helpful references: Using Components Collisions OnCollisionEnter() UI Canvas UI Text UI.Text

Hope this helps.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tom01098 · Nov 24, 2015 at 09:05 AM

You could create a canvas with a Text element inside. In your script, make sure you are:

 using UnityEditor.UI;

And then you can define

 public Text yourTextObject;

Drag and drop your text element into the section in the inspector.

In your code, if you have an int variable called score

 private void Update()
 {
     yourTextObject.text = "Score: " + score;
 }

To update the on screen score every frame. Hope this helped!

Comment
Add comment · Show 1 · 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 Tom01098 · Nov 24, 2015 at 09:05 AM 0
Share

This is using C#, by the way

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

36 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

Related Questions

How do I add a score system? 1 Answer

How do I make the Score system work? 1 Answer

Problem with counting score in 3D game 1 Answer

i made a game like temple run but when i fall from edge it loads restart menu but the score keep going 1 Answer

Scoring different amount of points 0 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