Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to fix 'Time' does not contain a definition for 'timeScale'

Discussion in 'Scripting' started by Greenfiregames971, Feb 5, 2023.

  1. Greenfiregames971

    Greenfiregames971

    Joined:
    Feb 5, 2023
    Posts:
    8
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class PauseMenu : MonoBehaviour
    7. {
    8.     public GameObject PauseObject;
    9.  
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.        
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         if(Input.GetKeyDown("escape"))
    20.         {
    21.             PauseObject.SetActive(true);
    22.             Time.timeScale = 0f;
    23.         }
    24.     }
    25. }
    26.  
     
  2. Greenfiregames971

    Greenfiregames971

    Joined:
    Feb 5, 2023
    Posts:
    8
    nvm i fixed it
     
  3. thennocent1

    thennocent1

    Joined:
    May 1, 2023
    Posts:
    6
    I've got the same Problem, how did you fix it?
     
  4. pixaware_pwedrowski

    pixaware_pwedrowski

    Joined:
    Oct 25, 2018
    Posts:
    116
    Make sure you are using UnityEngine -
    using UnityEngine;
    or you haven't made case-specific mistakes -

    Time.timeScale = .5f;
     
    unUmGong likes this.
  5. thennocent1

    thennocent1

    Joined:
    May 1, 2023
    Posts:
    6
    thank you for the fast answer, it does not work tho.
    do you have an other solution?
    here is my script:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PauseMenu : MonoBehaviour
    {
    public GameObject pauseMenu;
    public bool isPaused;


    // Start is called before the first frame update
    void Start()
    {
    pauseMenu.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
    if(Input.GetKeyDown(KeyCode.Escape))
    {
    if(isPaused)
    {
    ResumeGame();
    }
    else
    {
    PauseGame();
    }
    }
    }

    public void PauseGame()
    {
    pauseMenu.SetActive(true);
    Time.timescale = 0;
    isPaused = true;
    }

    public void ResumeGame()
    {
    pauseMenu.SetActive(false);
    Time.timescale = 1;
    isPaused = false;
    }
    }
     
  6. pixaware_pwedrowski

    pixaware_pwedrowski

    Joined:
    Oct 25, 2018
    Posts:
    116
    are you sure you haven't made a case-specific mistake here? check again this:
    Time.timescale = 0;
     
    Yoreki and unUmGong like this.
  7. thennocent1

    thennocent1

    Joined:
    May 1, 2023
    Posts:
    6
    well i made it with a video, i tried several options and none of it is working.
     
  8. pixaware_pwedrowski

    pixaware_pwedrowski

    Joined:
    Oct 25, 2018
    Posts:
    116
    unUmGong likes this.
  9. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,741
    Did you create a script of your own called "Time"? If so, rename it and the file that contains it.
     
    Bunny83 likes this.
  10. thennocent1

    thennocent1

    Joined:
    May 1, 2023
    Posts:
    6
  11. thennocent1

    thennocent1

    Joined:
    May 1, 2023
    Posts:
    6
    i did not.
     
  12. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    You're just making typing mistakes. Stop doing that because you will be REQUIRED to fix all of them.

    When you get an error, remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    Fortunately this is the easiest part to get right: Be a robot. Don't make any mistakes.
    BE PERFECT IN EVERYTHING YOU DO HERE!!


    If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

    Finally, when you have errors, don't post here... just go fix your errors! Go back to the top of this post!
     
  13. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    timescale =/= timeScale
     
    thennocent1 and AcidArrow like this.
  14. thennocent1

    thennocent1

    Joined:
    May 1, 2023
    Posts:
    6
    Thank you!

    The sipmliest comment I've ever seen.
    Some other guy wrote me a whole book about it and this simple comment changed everything.
     
  15. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,533
    You may criticise but to be fair, you were also told previously: https://forum.unity.com/threads/how...efinition-for-timescale.1396000/#post-9019339

    You'll find that the attutide on the forum is to provide you the information and for you to help yourself because long-term this is best for you.

    C# is case sensitive.
     
    Ryiah, Yoreki and Kurt-Dekker like this.
  16. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    While i appreaciate the thank you, i cant really take credit for the solution. As Melv said, it was mentioned before. Several times, actually. From "check this" to "are you sure, compare to docu" to "you are just making typos". They wanted you to find the mistake yourself, since, as Kurt said, it was just a typo, and you really really want to get used quickly to not making typos and be able to fix those yourself. I just couldnt watch anymore and thought i'd just make it absolutely clear beyond a doubt what people have been going on about for quite a few posts now. I dont write this with any ill intentions either, it can be easy to overlook some typos. But that's exactly why it's important to get used to that asap :)
     
    Bunny83, MelvMay and Kurt-Dekker like this.
  17. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,913
    As others hinted in this thread, I want to make it clear:

    From our previous experience, both when we were learning the craft and when we watched others learning the craft, we know that wanting the solution from us (or other help) isn't the good headspace. Most of the time we give guidance, so you can find the solution yourself. When we give out solution, we basically just work for you for free and you don't learn from it. When we guide you to the solution (or at least the direction) we try to teach you and not to be exploited for free labor.
    So my advice is: read that whole book, it is there for you to teach you something, learn from it.

    ps: Oh, and there is nothing wrong with not wanting to learn how to code. That's all right, but then hire a coder to take care of that part.
     
    Kurt-Dekker and Yoreki like this.
  18. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,134
    A simple comment can lead to quick results but if you don't understand what went wrong with your code you're just going to keep making that mistake. While I do think some of the responses could have been shorter or made more obvious they were trying to teach you how to avoid making that mistake again.

    An error saying that a definition doesn't exist is almost always a typo. C# is case sensitive which if you haven't seen that term before means it sees a lowercase "s" and an uppercase "S" as two different symbols. When you see that error you should immediately go to the line indicated and verify the word was entered correctly.

    Unity's API docs will have the correct capitalization if you're not positive what it should be.

    https://docs.unity3d.com/ScriptReference/Time-timeScale.html
     
    Last edited: May 18, 2023
    Yoreki likes this.