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 /
avatar image
0
Question by importguru88 · Aug 13, 2016 at 07:34 PM · timerscorescore systemhowbased

How do I code time based score unity3d

I want require points for the level . Right now I have it set for 100 point . The problem I am have is the scene is switch right when I reach 100 . The player a least got to have a 100 or what the amount in to move on to the next level. I also have a time and the timer gotta be done and the player has to have 100 or what points I have in the code before the timer is done. The timer is basically check to see if I have those points or not before the timer is done . The player can score as my points as long as if the player got the require points before the timer is done. I hope this make sense here is my code :

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class TestScript : MonoBehaviour
 {
     public MyClockScript myClock;
     public ScoreManagerScript scoremanager;
     
     public int scoreToReach = 100;     // change this value to what you want
     
     public string nextScene = "FY"; // change this value to what you want
 
     void Update () 
     {
         if (myClock.m_leftTime <= 0)
         {
             SceneManager.LoadScene(SceneManager.GetActiveScene().name); // reload the current scene because ran out of time
         }
         else if ((ScoreManagerScript.score >= scoreToReach) && (nextScene != "FY"))
         {
             SceneManager.LoadScene(nextScene);
         }
     }
 }
 

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

3 Replies

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

Answer by Happy-Zomby · Aug 13, 2016 at 09:44 PM

Do you mean you always want the counter to run down to zero before checking the score? if so, something like this should work

  if (myClock.m_leftTime <= 0)
              {
              if ((ScoreManagerScript.score >= scoreToReach) && (nextScene != "FY"))
                     {
                     SceneManager.LoadScene(nextScene);
                     }
              else
                    {
                    SceneManager.LoadScene(SceneManager.GetActiveScene().name);
                    }
               }
 

hope that helps,

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 importguru88 · Aug 13, 2016 at 10:56 PM 0
Share

Yes . That what I mean . The problem is that is only went off of this code :

When it reach zero it reset the scene . It's didn't check for points

Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().name);

avatar image
0

Answer by afonsolfm · Aug 13, 2016 at 11:04 PM

You could use the Invoke function.

When the level starts, you can use Invoke like this:

 void NewLevel() {
     Invoke("CheckReachedScore", clockTime);
 }

 void CheckReachedScore()
 {
     if (scoremanager.score >= scoreToReach) {
         // It has reached the score
     } else {
        // It has not 
     }
 }

Your code is a little messy, but I hope made my point giving the general idea of how to handle this.

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 importguru88 · Aug 14, 2016 at 02:55 AM 0
Share

I got the scene to switch when the points reach and the timer reaches zero. I only need an else statement so I can switch scenes when the points are less when timer reach zero . Here is what I got right now for code :

When I get a lesser score than score reach plays this code :

 Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().name);

I need this part here in a else statement the scene switch in the if statement:

  if (myClock.m_leftTime <= 0)
                   {
                   if ((Score$$anonymous$$anagerScript.score >= scoreToReach) && (nextScene != ""))
                          {
 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using UnityEngine.Scene$$anonymous$$anagement;
 
 public class TestScript : $$anonymous$$onoBehaviour
 {
     public $$anonymous$$yClockScript myClock;
     public Score$$anonymous$$anagerScript scoremanager;
     
     public int scoreToReach = 99;     // change this value to what you want
     public int leastscore = 50;
     public string nextScene = "FY"; // change this value to what you want
 
     void Update () 
     {
           if (myClock.m_leftTime <= 0)
               {
               if ((Score$$anonymous$$anagerScript.score >= scoreToReach) && (nextScene != ""))
                      {
                      Scene$$anonymous$$anager.LoadScene(nextScene);
                      }
               else
                     {
                     Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().name);
                     }
                }
  
     }
     
 }   
     
 



avatar image
0

Answer by FabriBertani · Aug 13, 2016 at 11:05 PM

You're saying in the else if statement that if the score is greater than OR IQUAL to 100, change the level. I would try something like this e.g.

  using UnityEngine;
  using System.Collections;
  using UnityEngine.UI;
  using UnityEngine.SceneManagement;
  
  public class TestScript : MonoBehaviour
  {
      public MyClockScript myClock;
      public ScoreManagerScript scoremanager;
      
      public int scoreToReach = 100; 
  
      void Update () 
      {
          if (myClock.m_leftTime <= 0)
          {
              SceneManager.LoadScene("thisScene");
          }
          //I don't like the else if statement...
          if (ScoreManagerScript.score == scoreToReach)
          {
              //Print some GUI message here
             Debug.Log("Press Enter to change level or keep playing");
          }
          if ((Input.GetKeyDown(KeyCode.Return)) && (ScoreManagerScript.score >= scoreToReach))
          {
             SceneManager.LoadScene("nextScene");
          }
      }
  }
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

56 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 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 do I do I time-base score script 0 Answers

Pause Time.time? 1 Answer

How to give points after certain number of seconds?,How to give points after a certain number of seconds? 1 Answer

3 star time base system 0 Answers

How do you stop a score counter when you die 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