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 lemiwinks · Aug 05, 2013 at 04:48 PM · scorescore system

Unknown issue with score system

hey all, so im working on a score system for my game and came across a small issue. now depending on the amount of shots taken, the player will be awarded 1 to 4 stars. (4 being the best), now my script worked fine when i just had a debug.log that said the number of stars won. however now ive added in the GUI graphics and it doesn't work, only one star shows up nomatter what the score is :S

here is a shot of my gui http://i.imgur.com/y1AFeuI.png

and here is the code i wrote, any ideas?

 using UnityEngine;
 using System.Collections;
 
 
 public class Hole_TouchDestroy : MonoBehaviour {
     
     public GUITexture ScoreBack;
     public GUITexture Star1;
     public GUITexture Star2;
     public GUITexture Star3;
     public GUITexture Star4;
     public GUITexture StarSurround;
     
     
     
     void OnTriggerEnter(Collider other) {
         Destroy(other.gameObject);
         Debug.Log(DragShotMover.parCount);
         
         ScoreBack.enabled = true;
         
         if (DragShotMover.parCount <= 2 )
             Debug.LogWarning("4 Stars");
             Star1.enabled = true;
             Star2.enabled = true;
             Star3.enabled = true;    
             Star4.enabled = true;
             StarSurround.enabled = true;
         
         if (DragShotMover.parCount == 3 )
             Debug.LogWarning("3 Stars");
             Star1.enabled = true;
             Star2.enabled = true;
             Star3.enabled = true;    
             Star4.enabled = false;
             StarSurround.enabled = false;    
         
         if (DragShotMover.parCount == 4 )
             Debug.LogWarning("2 Stars");
             Star1.enabled = true;
             Star2.enabled = true;
             Star3.enabled = false;    
             Star4.enabled = false;
             StarSurround.enabled = false;    
         
         if (DragShotMover.parCount >= 5 )
             Debug.LogWarning("1 Star");
             Star1.enabled = true;
             Star2.enabled = false;
             Star3.enabled = false;    
             Star4.enabled = false;
             StarSurround.enabled = false;
         
         //Application.LoadLevel(1);
         
         
         
         
         
         
         DragShotMover.parCount = 0;
     }
     
     
 }
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
2
Best Answer

Answer by robertbu · Aug 05, 2013 at 05:17 PM

You are missing {} around all of your if statements. That is, the only thing that is controlled by your if statements is the Debug.Log() call. All other lines are executed, and the last set of lines is for one star. But even if you had your brackets, you would need 'else' clauses to get the logic right. Try this simplification instead:

 public class Hole_TouchDestroy : MonoBehaviour {
  
     public GUITexture ScoreBack;
     public GUITexture Star1;
     public GUITexture Star2;
     public GUITexture Star3;
     public GUITexture Star4;
     public GUITexture StarSurround;
  
     void OnTriggerEnter(Collider other) {
         Destroy(other.gameObject);
         Debug.Log(DragShotMover.parCount);
         
         ScoreBack.enabled = true;
         
         var count = DragShotMover.parCount;
         StarSurround.enabled = Count <= 2;
         Star1.enabled = count <= 2;
         Star2.enabled = count <= 3;
         Star3.enabled = count <= 4;
         Star4.enabled = count <= 5;
         
         DragShotMover.parCount = 0;
     }
 }
Comment
Add comment · Show 5 · 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 lemiwinks · Aug 05, 2013 at 05:24 PM 0
Share

i knew it would of been something simple, been staring at the screen all day! lol Thankyou for your help, and thankyou even more for simplifying the script, works great!

avatar image lemiwinks · Aug 05, 2013 at 05:27 PM 0
Share

ooh small question.. my next step is to make a 1 or 2 seconds to pass before each star is enabled, so 1 star would show, wait for 1 second, second star shows ect. How would i go about this using this script?

avatar image robertbu · Aug 05, 2013 at 05:33 PM 1
Share

You would put this between your enabled calls:

 yield WaitForSeconds (1.0);
avatar image lemiwinks · Aug 05, 2013 at 05:48 PM 0
Share

thankyou :)

avatar image clunk47 · Aug 05, 2013 at 10:54 PM 0
Share

Damn got to it before me lol

+1

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

15 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

Related Questions

Multiple Cars not working 1 Answer

Scoring help ! 1 Answer

Score System help 1 Answer

How to add score after destroying object in unity 2D? 1 Answer

Add score when enemy is killed? 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