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 oldnavy281 · May 30, 2019 at 01:01 PM · scripting problemscript.bug

timeScale is being set to 1 instead of staying set at 0,How to fix the timeScale?

alt text

I'm having a problem with the script above. The problem is that when the script is run (the script is on a separate canvas), the timeScale of the canvas that is being overlapped by the script canvas' timeScale is being set to 1, when the timeScale should be set to 0. In short, the background of the canvas where the script is, is setting its own timeScale to 1 instead of setting and keeping the timeScale at 0, where it should be when the script canvas is called...

Anyone have any ideas how to fix this?,alt text

I'm having a problem with this code that I can't figure out. The problem is when I run the scene in Unity, once the script above is called (the script itself is on another canvas), the canvas in the background's timeScale gets set to 1. The canvas in the background's timeScale is supposed to be set to 0 when the canvas where the script is on is opened, but the timer sets the timescale back to 1...

Anyone have any ideas on how to possibly fix this?

code.png (21.0 kB)
code.png (21.0 kB)
Comment
Add comment · Show 1
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 xxmariofer · May 30, 2019 at 01:54 PM 0
Share

i dont really understand your issue, you mean that the timescale of one canvas is 0 and the other is 1? the timescale is being set back to 1because i imagine by opened you mean active and you are setting the timescale to 1 in the start

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by oldnavy281 · May 30, 2019 at 01:56 PM

so there is an object in the game that once destroyed sets time scale to 0. And then a canvas appears that has a timer. Since the time scale is set to 0 the timer doesn't work, but the time scale needs to be set to 0 for other aspects of the game. Is there a way to allow the timer to has timescale of 1 for example, while the rest of the game is set to timescale of 0?

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

Answer by xxmariofer · May 30, 2019 at 02:12 PM

Here you have the code just override your coroutine

 IEnumerator LoseTime()
 {
     while (timeLeft> 0) {
         yield return null;
         timeLeft -= Time.unscaledDeltaTime;
     }
 }
Comment
Add comment · Show 2 · 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 oldnavy281 · May 30, 2019 at 02:22 PM 0
Share

I received an error after I edited the code. This is the error:

Assets/$$anonymous$$ath Blasters/Assets/Start $$anonymous$$enu/Timer.cs(26,21): error CS0266: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?)

The updated code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using System.Threading;
 
 public class Timer : $$anonymous$$onoBehaviour {
 
     public int timeLeft = 30; //Seconds Overall
     public Text countdown; //UI Text Object
 
     void Start () {
         StartCoroutine("LoseTime");
         Time.timeScale = 1; //Just making sure that the timeScale is right
     }
 
     void Update () {
         countdown.text = ("" + timeLeft); //Showing the Score on the Canvas
     }
 
     //Simple Coroutine
     IEnumerator LoseTime()
     {
         while (timeLeft > 0) {
             yield return null;
             timeLeft -= Time.unscaledDeltaTime; 
         }
     }}

avatar image xxmariofer oldnavy281 · May 30, 2019 at 02:37 PM 0
Share

change public int timeLeft to public float timeLeft

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

269 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 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 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

Menu object not responding 0 Answers

Unity {[(2D)]} RotateAround while jumping 0 Answers

How to make a boat move without controling it ? 0 Answers

Auto Set vs Manual Decrease (How to do both?) 1 Answer

How can I fix this animation flick 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