• 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
1
Question by Kevvchiks · Nov 18, 2015 at 03:18 PM · scorescoreboarddisplacement

HOW TO ADD ONSCREEN SCORE

HELLO, i have scoring script who count score when i collect coins.

 #pragma strict
 import UnityEngine.UI;
 // JavaScript
 var score = 0;
 
 function OnTriggerEnter( other : Collider ) {
     Debug.Log("OnTriggerEnter() was called");
     if (other.tag == "coin") 
     {
         Debug.Log("Other object is a coin");
         score += 5;
         Debug.Log("Score is now " + score);
         Destroy(other.gameObject);
     }
 }
 
 function OnGUI() 
 {
     GUILayout.Label( "Score = " + score );
 }


And i have one problem - how can i display my score on screen?

Comment
Add comment · Show 10
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 Jessespike · Nov 18, 2015 at 04:12 PM 1
Share

This code does show a score on screen. The OnGUI function should be working. Unless I'm misunderstanding the question, what is the problem?

avatar image Kevvchiks Jessespike · Nov 18, 2015 at 08:25 PM 1
Share

score is counting, but it doesn't appear on screen

Show more comments
avatar image Soos621 · Nov 18, 2015 at 08:49 PM 0
Share

you will need to set the Rect of the label so that it appears on the screen, use screen.height and screen.width to find and set your initial position of the Rect and then add to it the size of the rect's height and width. Though using unity's built in UI system is much easier and will resize your UI components. https://unity3d.com/learn/tutorials/topics/user-interface-ui

avatar image Kevvchiks Soos621 · Nov 18, 2015 at 08:52 PM 0
Share

Can you show me how it looks in script? I'm beginner in Unity

Show more comments
avatar image Kevvchiks Soos621 · Nov 18, 2015 at 09:08 PM 0
Share

Can u make it in my script?

avatar image ocimum · Nov 19, 2015 at 10:42 AM 0
Share

Normally you don't need a Rect inside the Label contructor. Inserting a string the Label will be displayed in the upper left corner because it will be setup at x: 0 and y: 0 Where did you attach the script?

0 Replies

· Add your reply
  • Sort: 

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

37 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

Related Questions

How do I add a score system? 1 Answer

How do I make the Score system work? 1 Answer

How do you save scores and update a scoreboard with them? 0 Answers

Problem with ScoreBoard in Ping Pong game 1 Answer

My score system doesn't display or work? Please help me! 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