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
1
Question by Calum1015 · Feb 24, 2015 at 03:35 AM · buttoncollision detectionontriggerenterpointspoints-counter

Points system for unity

Hello, I am looking for advice for a points system. I have tried a couple things but they aren't working very well at all. First of all I am trying to create a planet system, when you hit a planet an audio clip and an animation plays. I have tried with two different scripts. Here are those scripts.

     var PlayerScore : int;
      var ScoreText = "Score: 0";
      var MaxPoints : int;
      
      function OnTriggerEnter(other : Collider){
          if(other.tag == "Point"){
              PlayerScore += 1;
              ScoreText = "Score: " + PlayerScore;
              Destroy(other.gameObject);
          }
      }
      
      function Update(){
          if(PlayerScore > MaxPoints){
              PlayerScore = 0;
              print("MaxReached");
              ScoreText = "Score: 0";
          }
          GUI.Button(Rect(0,0,10,10),"Start");
      }


this did not work. In this script my goal was that after the player got to 10 points while receiving 1 point each time they hit a planet a start button would appear. A score counter was supposed to appear in the corner of the screen. The script didn't do anything when I attached it to the planets, do I need to attach it to the player? If not if someone could help me with this that would be great. Thanks!

Comment
Add comment · Show 2
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 NoseKills · Feb 24, 2015 at 07:47 AM 2
Share

If you have 'Playerscore' in this script, you need to have just one instance of this script for it to be useful. So I'd say attach it to the player. If you attach this to every planet, then every planet will have a Playerscore that will increase by 1 when you hit the planet. You'd have to hit one planet 10 times to get its score to 10.

Also you're trying to constantly draw the start button in Update, not just when playerScore>$$anonymous$$axPoints. Also I believe drawing GUI.xxx elements only works inside OnGUI() method, not Update().

avatar image Calum1015 · Feb 24, 2015 at 02:53 PM 0
Share

Hanks for the help! I really appreciate this!

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by toddisarockstar · Feb 24, 2015 at 08:21 AM

NoseKill is right. i gave him a thumbs up. you have to use buttons in a separate function. make sure your planets have colliders and your player has collider and rigidbody cpmponents. assuming everything else in you script is working the adjustment would look like this :

       var PlayerScore : int;
       var ScoreText = "Score: 0";
       var MaxPoints : int;
       var gobutton=false;
       function OnTriggerEnter(other : Collider){
           if(other.tag == "Point"){
               PlayerScore += 1;
               ScoreText = "Score: " + PlayerScore;
               Destroy(other.gameObject);
           }
       }
       
       function Update(){
           if(PlayerScore > MaxPoints){
               gobuttons=true;
               PlayerScore = 0;
               print("MaxReached");
               ScoreText = "i got"+PlayerScore;
           }}
 
 function OnGUI () {
 
 if(gobuttons){
           if(GUI.Button(Rect(0,0,10,10),"Start")){PlayerScore=0;gobutton=false;}
    GUI.Label(Rect(Screen.width*0.5,Screen.height*0.5,20,20),ScoreText);}}
  

Sorry i didnt test it. let me know if it works now.

Comment
Add comment · Show 6 · 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 Calum1015 · Feb 24, 2015 at 02:52 PM 0
Share

Thanks for the help, I will try it later today!

avatar image Calum1015 · Feb 25, 2015 at 12:32 AM 0
Share

No, says there are a few compiler errors, once I debug it I will try again!

avatar image Calum1015 · Feb 25, 2015 at 12:33 AM 0
Share

It says there is an unknown identifier "gobuttons"

avatar image Calum1015 · Feb 25, 2015 at 12:40 AM 0
Share

Okay I found the issue, you forgot the quotation marks in

if(gobuttons) {

It still is not working though. When ever I hit a planet it just lets me stay on the planet, ins$$anonymous$$d of destroying the planet gameObject and passing through. I just collide with the planet.

avatar image toddisarockstar · Feb 27, 2015 at 12:46 AM 0
Share

oh sorry you might have to say the destroy line like this:

 Destroy (hit.collider.gameObject);


Show more comments
avatar image
0

Answer by MjrDeathAdder · Feb 27, 2015 at 02:16 AM

GUI functions/commands are required to be in a void OnGUI(){ } function. This looks like your problem. This is an addition to toddisarockstar's answer.

Comment
Add comment · Show 2 · 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 Calum1015 · Feb 27, 2015 at 03:10 PM 0
Share

Isn't void OnGUI C#? Sorry I'm new to JavaScript.

avatar image toddisarockstar · Mar 03, 2015 at 03:16 AM 0
Share

i am all javascript. it would be good for me to learn a little C#, but i know there is no need for the term "void" in any javascript!

the "void" term is a C# sharp thing.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Having difficulties making a block be a death trigger for a ball. 2 Answers

I am trying to give my player points when an enemy dies 1 Answer

OnTriggerEnter not working in running game 4 Answers

How can I make my score counter increase incrementally and not jump from 0 to 100? 2 Answers

Double Score Problem ? 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