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 KCG00 · Jan 23, 2016 at 10:34 PM · timerscore systemcountup

Scoring based on count up timer

can anyone help .. im try to make a countup timer, that when the play finish the level the time stop and base on that time the player finishes the a score of (1,2 or 3) stars ..

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 Cepheid · Jan 24, 2016 at 01:02 AM

@KCG00 Well, you would start by simply deciding what times the player should receive certain stars and then evaluate your timer at the end to decide if they have met the condition to recieve a star. So for a quick example let's say:

  • 20 seconds - they get a gold star.

  • 40 seconds - they get a silver star.

  • 60 seconds - they get a bronze star.

Now that we know what time's make up a star we simply check our timer in our code after the level is finished and evaluate it against those conditions. So, a really rough setup would look something like this:

     // Our initial timer variable which will store our time.
     float timer = 0;
 
     void Update ()
     {
         // Timer begins counting up from 0.
         timer += Time.deltaTime;
     }
 
     void LevelFinished ()
     {
         // Is the time less than or equal to 20 seconds?
         if(timer <= 20f)
         {
             print("Player get's a gold star!");
         }
         // Is the time less than or equal to 40 seconds, 
                 //but greater than 20 seconds?
         else if(timer <= 40f && timer > 20f)
         {
             print("Player get's a silver star!");
         }
         // Is the time less than or equal to 60 seconds, 
                 //but greater than 40 seconds?
         else if(timer <= 60f && timer > 40f)
         {
             print("Player get's a bronze star!");
         }
         // The timer has counted too far for the player to get a star.
         else 
         {
             print("Player get's nothing!");
         }
     }

Now, all going well it should print the appropriate message after the correct times have been met. Now, there are more elegant and cleaner solutions to doing this, but this should hopefully give you a good rough idea of how to implement the mechanic.

Comment
Add comment · Show 1 · 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 KCG00 · Feb 03, 2016 at 08:31 PM 0
Share

thanks really appreciate it , but i was try to incorporate into this code that shows the time on the camera screen. how would i go about that or do i even need these codes.

this the Timer Script

     startTimer = Time.time;
     PlayerPrefs.SetInt("Level_2", 1);
     PlayerPrefs.SetInt("Level_1_Score", TimeScore);
     
 }

 // Update is called once per frame
 void Update() {

     float t = Time.time - startTimer;

     string $$anonymous$$utes = ((int)t / 60).ToString();
     string seconds = (t % 60).ToString("f2");

     timerText.text = $$anonymous$$utes + ":" + seconds;





     }


which it gets the score settings from the my Level $$anonymous$$anager

 void FillList()
 {
     foreach (var level in LevelList)
     {
         GameObject newbutton = Instantiate(levelButton) as GameObject;
         LevelButtons button = newbutton.GetComponent<LevelButtons>();
         button.LevelText.text = level.LevelText;
         //Level_1, Level_2,Level_3,Level_4,Level_5

        if(PlayerPrefs.GetInt("level_" + button.LevelText.text) == 1)
         {
             level.Unlocked = 1;
             level.IsInteractable = true;
         }

         button.unlocked = level.Unlocked;
         button.GetComponent<Button>().interactable = level.IsInteractable;
         button.GetComponent<Button>().onClick.AddListener(() => loadLevels("Level_" + button.LevelText.text));

          if (PlayerPrefs.GetInt("Level_1_Score" + button.LevelText.text + "_score") > 20)  
         {
             button.Star1.SetActive(true);
         }

         if (PlayerPrefs.GetInt("Level_1_Score" + button.LevelText.text + "_score") >= 20)
         {
             button.Star2.SetActive(true);
         }

         if (PlayerPrefs.GetInt("Level_1_Score" + button.LevelText.text + "_score") >= 20)
         {
             button.Star3.SetActive(true);
         } 

   

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

41 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to add one score every second to scoremanager c# 1 Answer

Looking for a simple Score Multiplier. 1 Answer

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

Hey i am trying to add a time score system and time high score system need help. 0 Answers

Saving and displaying best time per level. 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