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 SlyyGuyy · Oct 07, 2012 at 11:18 PM · javascriptscore

Scoring System Java

Hey guys,

I'm currently working on a game and I'm working on implementing a scoring system in my game and it's not appearing properly. I've attached a picture to show what's happening and where the score is showing up and where I would like the score to actually be. The score is appearing on the far left of the screen and I would like it to be contained inside the black box on the playing field. My code is as follows:

 private var playerScore : int;
 var scoreStyle : GUIStyle;
 
 function Start () {
     renderer.material.color = Color.black;
 }
 
 function Update () {
 
 }
 
 function OnGUI() {
     GUILayout.BeginArea(Rect(10,10, Screen.width/2, Screen.height/2));
     GUILayout.Box(playerScore.ToString(), scoreStyle);
     GUILayout.EndArea();
 }
 
 function Score() {
     playerScore = 0000;
 }
 
 
 function OnTriggerEnter(collision:Collider) {
     if (collision.gameObject.tag == "Zs")
     {
         playerScore += 10;
     }
 }

Thank you all in advance for your help on this subject and I hope the community can be of assistance. Much appreciated again. - Slyy [1]: /storage/temp/3996-scorehelpunity.jpeg

scorehelpunity.jpeg (15.8 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by T27M · Oct 08, 2012 at 10:19 PM

This black box that is highlighted, how have you created this? It looks like a drawing? The picture isn't very clear.

Your piece of code that you have used to create your area:

 GUILayout.BeginArea(Rect(10,10, Screen.width/2, Screen.height/2));

Your Rect will start 10 from the left and 10 down in screen coordinates, with a width and height that is half the screen width and height respectively. I cant see any code that has created the box you have highlighted.

`GUILayout.Box(playerScore.ToString(), scoreStyle);`

Starts in the area exactly where you have told it to. Take a look at the docs again and move your area or box to fit where you need, keep in mind its going to be a different place for different screen resolutions.

http://docs.unity3d.com/Documentation/ScriptReference/GUILayout.BeginArea.html

Comment
Add comment · Show 3 · 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 SlyyGuyy · Oct 08, 2012 at 10:21 PM 0
Share

That's what I thought about the area...but also why is it only showing 1 zero ins$$anonymous$$d of the 0000 that I have set as the player score? And the box that is highlighted in the picture is a Cube GameObject which now that I'm thinking about it, doesn't really make sense to apply a score to. Or can that still work?

avatar image T27M · Oct 08, 2012 at 10:31 PM 0
Share

When you say apply your score to it what do you mean? The object the script is attached to ?

Also it shows 0 because 0000 is just another way of saying 0. You need to format your string if you want more than one 0.

avatar image SlyyGuyy · Oct 08, 2012 at 10:36 PM 0
Share

When I say apply my score to it, I do indeed mean the object that script is attached to...I also did not know that it would revert to that. Thank you

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

11 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

Related Questions

Issue with PlayerPrefs and local highscore 3 Answers

I am creating a pause button and when I click it the score keeps rising. How can I stop it? 1 Answer

A fancier method to add numbers 1 Answer

Keeping track of items 1 Answer

Trying to make simple trigger score counter, having troubles. 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