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 robbos729 · Jul 28, 2019 at 10:37 AM · timerscorecountdown

When Score goes up by 25 change timer value

In my Game i want to make it for every 25 points the timer goes down by 0.25 seconds. How cn i do this with these 2 sets of codes?

 using UnityEngine;
 using UnityEngine.UI;
 
 public class KeepScoreManager : MonoBehaviour
 {
     public Text ScoreText;
     private int score;
     public Text NewBest;
 
 
 
     public void IncreaseScore(int increment)
     {
        NewBest.text = PlayerPrefs.GetInt("NewBest").ToString();
 
         score += increment;
         if (score > PlayerPrefs.GetInt("NewBest"))
         {
             PlayerPrefs.SetInt("NewBest", score);
             NewBest.text = PlayerPrefs.GetInt("NewBest").ToString();
         }
 
         ScoreText.text = score.ToString();
     }
 }

and the timer;

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class CountdownScript : MonoBehaviour
 {
     [SerializeField] private Text uiText;
     [SerializeField] private float mainTimer;
     [SerializeField] private GameObject panel;
 
     void Start()
     {
         timer = mainTimer;
     }
 
     public float timer;
     private bool canCount = true;
     private bool doOnce = false;
 
     void Update()
     {
         if (timer >= 0.0f && canCount)
         {
             timer -= Time.deltaTime;
             uiText.text = timer.ToString("F");
         }
 
         else if (timer <= 0.0f && !doOnce)
         {
             canCount = false;
             doOnce = true;
             uiText.text = "0.00";
             timer = 0.0f;
             panel.SetActive(true);
         }
     }
 
     public void ResetBtn()
     {
         timer = mainTimer;
         canCount = true;
         doOnce = false;
     }
 }


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 I_Am_Err00r · Jul 30, 2019 at 02:24 PM

 using UnityEngine;
  using UnityEngine.UI;
  
  public class KeepScoreManager : MonoBehaviour
  {
      public Text ScoreText;
      private int score;
      CountdownScript countdown;
      public Text NewBest;
  
     private void Start()
 {
 countdown = GameObject.FindObjectOfType<CountdownScript>();
 }
  
      public void IncreaseScore(int increment)
      {
         NewBest.text = PlayerPrefs.GetInt("NewBest").ToString();
  
          score += increment;
          changeTime += increment;
          if (score > PlayerPrefs.GetInt("NewBest"))
          {
              PlayerPrefs.SetInt("NewBest", score);
              NewBest.text = PlayerPrefs.GetInt("NewBest").ToString();
          }
  
          ScoreText.text = score.ToString();
          if(changeTime >= 25)
         {
              countdown.ChangeTime();
              changeTime = 0;
         }
      }
  }

And then somewhere in your CountdownScript, add this:

 public void ChangeTime()
 {
 timer -= .25f //You could also assign a public variable in case you want this value different at times, but this should do what you are asking.
 }
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 robbos729 · Aug 06, 2019 at 08:59 PM 0
Share

Sorry for late reply went on holiday however with the script it says the name ChangeTime does not exist in this context so will I need to do a gameobject.getcomponent or something to link that part of the keepscoremanager script

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

112 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 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 to restart a level with countdown? 4 Answers

How to stop a countdown from counting down 1 Answer

countdown timer acivation 1 Answer

Lerpz Escapes question 1 Answer

countdown timer on for example a wall of a building in your game? 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