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 annastachtiari · Feb 19, 2016 at 12:30 AM · c#scripting problemscore

Grading system not working

Hello everyone,

I am trying to create a grading system on my game so by the end of it, depending on the score, the user gets the matching grade. Bare with as I am very new at scripting still...

using UnityEngine.UI; using UnityEngine; using System.Collections;

public class GradeScript : MonoBehaviour {

 private GameController gameController;
 public Text gradeText;

 void Awake () {
     
 gameController = FindObjectOfType<GameController>();
     
 }
 
 void Update () {
 
     if (gameController.score > 700) {
     gradeText.text = "Grade: A+";
     }
     
     if (gameController.score > 600 && gameController.score < 699) {
         gradeText.text = "Grade: A";
     }
     
     if (gameController.score > 500 && gameController.score < 599) {
         gradeText.text = "Grade: B";
     }
     
     if (gameController.score > 400 && gameController.score < 499) {
         gradeText.text = "Grade: C";
     }
     
     if (gameController.score > 300 && gameController.score < 399) {
         gradeText.text = "Grade: D";
     }
     
     if (gameController.score > 200 && gameController.score < 299) {
         gradeText.text = "Grade: E";
     }
     
     if (gameController.score > 100 && gameController.score < 199) {
         gradeText.text = "Grade: F";
     }
 
 }

}

This is not working for me. I am getting no errors but it's not showing up in the final scene (Grading scene). Can you please help me? Thank you.

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
1

Answer by jgodfrey · Feb 19, 2016 at 12:52 AM

I don't necessarily see anything wrong with your code, though it's a lot more verbose than necessary. The following is probably a little cleaner (though typed directly into the forum and untested).

 void Update()
 {
    int score = gameController.score; 
    if (score > 700) { gradeText.text = "Grade: A+"; }
    elseif (score > 600) { gradeText.text = "Grade: A"; }
    elseif (score > 500) { gradeText.text = "Grade: B"; }
    elseif (score > 400) { gradeText.text = "Grade: C"; }
    elseif (score > 300) { gradeText.text = "Grade: D"; }
    elseif (score > 200) { gradeText.text = "Grade: E"; }
    else { gradeText.text = "Grade: F"; }
 }

Additionally, you probably need to add some Debug.Log statements to see what's going on. For instance, is the score value what you expect it to be? Also, this seems like a strange thing to be doing in Update(). Is that really what you want?

Comment
Add comment · Show 4 · 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 jgodfrey · Feb 19, 2016 at 01:14 AM 0
Share

One additional comment:

With your current, code, the following values will not match any of your checks:

600, 699, 500, 599, 400, 499, 300, 399, 200, 299, 100, 199, or anything < 100

avatar image annastachtiari jgodfrey · Feb 19, 2016 at 06:51 AM 0
Share

Thank you for replying! It is still not working, and I don't understand why. I am getting the following error in the console as soon as I reach the grading scene/ win scene: alt text

Could the problem be because I am using a script from another scene?

screen-shot-2016-02-19-at-065056.png (81.4 kB)
avatar image annastachtiari jgodfrey · Feb 19, 2016 at 06:54 AM 0
Share

Ok I just figured out what is happening: If I have the game object which contains the gameController script in the scene, it is working. However, the score values are not the same. I need to somehow reference the game Object as it is in the previous scene.

avatar image annastachtiari jgodfrey · Feb 19, 2016 at 07:10 AM 0
Share

Alright, never $$anonymous$$d. I found a different way into it. Ins$$anonymous$$d of changing the scene, I'm having a panel pop up showing the grade and it's working perfectly. Again, thanks for aaaall your help!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

PlayerScore prefab in unity gives value in gameover screen as 0, how do I show the final value in GameOver scene? 0 Answers

Score value in GameOver screen is 0 instead of final value from the Game Level scene(used PlayerPrefs), how do I display the final value from Game Level scene in the GameOver scene? 1 Answer

Score counter not working properly. 1 Answer

I need help with my script please 1 Answer

The laser problems 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