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 FiliBu5ter · Sep 06, 2016 at 01:40 PM · c#scoretagsscore system

Scoring system not working.

I've been trying to make a capital guessing game and am stuck on scoring.

There are four buttons, one of which is tagged "Correct Answer" and the rest are tagged "Wrong Answer".

Here's the script attached to the buttons:

 public class ButtonController : MonoBehaviour
 {
     public Score score;
     public SetUI setUI;
     public int correctValue = 10;
     public int wrongValue = 5;
     public Button button;
 
 
     void AnswerCheck ()
     {
         if (button.tag == "Correct Answer") 
         {
             score.currentScore += correctValue;
         } 
         else if (button.tag == "Wrong Answer")
         {
             score.currentScore -= 5;
         }
     }
 
     void OnClick ()
     {
         AnswerCheck ();
     }        
 }

Here's the score script referenced:

 public class Score : MonoBehaviour
 {
     public Text scoreText;
     public int currentScore = 0;
 
     void Start ()
     {
         scoreText.text = "Score: " + currentScore;
     }
 
     void Update ()
     {
         Debug.Log (currentScore);
     }
 }

Everything is tagged correctly and I don't know what the problem is. I've tried to use bool's and the Update function, but that made things worse.

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 Sonky108 · Sep 06, 2016 at 02:51 PM 0
Share

Have You attached Your method to buttons? Debug.Log returns 0 or something else?

avatar image FiliBu5ter Sonky108 · Sep 06, 2016 at 03:51 PM 0
Share

I have and when I press the correct button nothing happens.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Greg_lrgg · Feb 28, 2018 at 12:28 AM

Hmmm to be honest i don't see what's wrong with your code right now, however i can tell you how i proceeded to make mine in an arcade game. The scoring systems works as of now. I put the score as private inside the "Score" script, and simply call an Addscore function which is inside the "Score" script from the targets that gets destroyed:

 public GUIText scoreText;
 private int score;
 
 public void AddScore(int ScoreValue)
     {
         score += ScoreValue;
         UpdateScore();
     }
 
     private void UpdateScore()
     {
         scoreText.text = "Score:" + score;
     }

Comment
Add comment · 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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Highscore table C# HELP!!! 0 Answers

Highscore and PlayerPrefs unity C# 1 Answer

Highscore system unity C# 0 Answers

How do I add my Timer to my Score system in C# ? 0 Answers

Score counted multiple times when several projectiles impact the same target 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