Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
2
Question by d3thdrug · Feb 21, 2014 at 09:51 PM · animationunity 2dpause

Can I make an animation while game is paused?

Hi, I'm using unity 2d and I have a pause function which just makes the time scale switch to 0 (and then to 1, when activated again). Now the whole game is stopped even the animations. What I wanna do is just have an animation when it is paused but obviously it doesn't work because it's paused. Is there a way where I can do that, maybe by just letting that animation contradict? Can someone please gimme any suggestions?

here is the code I have if anyone wants to see c##

void Update () {

     if(Input.GetKeyUp(KeyCode.P))
     {
         paused = !paused;

     }

     if (paused) {
                     Time.timeScale = 0;

         anim.SetTrigger ("paused");

             } else {
                     Time.timeScale = 1;
         showControls = 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

3 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Maui-M · Feb 21, 2014 at 10:20 PM

Instead of using Time.timescale just run different parts of your code depending on if your game is paused or not.

 void Update () {
     if(Input.GetKeyUp(KeyCode.P)) {
        paused = !paused;
     }
  
     if (paused) {
        // Run pause code here
        anim.SetTrigger ("paused");
       } else {
        // Run game code here
        showControls = false;
      }
 }
Comment
Add comment · Show 3 · 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 immersiveGamer · Feb 22, 2014 at 03:02 AM 0
Share

Yup, you will be happier if you go with making your own pause logic and not messing with the timescale. I like to make either a static class or singleton to manage pausing and other game states.

avatar image d3thdrug · Feb 23, 2014 at 06:55 AM 0
Share

how do i do that?

avatar image immersiveGamer · Feb 23, 2014 at 11:25 AM 0
Share

Well a singleton will be simpler. $$anonymous$$ake a custom class with a static variable of the class and then instantiate the class in the static variable. This way you have the class inside of it's self and can access all of the class from anywhere.

     //manager classs with singleton
     public class Game$$anonymous$$anager
     {
         public static Game$$anonymous$$anager instance = new Game$$anonymous$$anager();
         
         public bool paused = false;
         
         public void TogglePause()
         {
             paused = !paused;
         }
         
         public void PauseGame()
         {
             paused = true;
         }
         
         public void UnpauseGame()
         {
             paused = false;
         }
     
     }
     
     //other script you are using 
     public class $$anonymous$$yGameScript : $$anonymous$$onobehaviour
     {
         //stuff
         
         void Update()
         {
             //This will pause and unpause the game.
             if(Input.Gey$$anonymous$$ey("P"))
                 Game$$anonymous$$anager.instance.TogglePause();
         
             if(Game$$anonymous$$anager.instance.paused == false)
             {
                 //logic you want to run when paused.
             }
             else
             {
                 //funcatlity to run when the game is paused.
             }
         }
         
         //more stuff
     }
 
  
 
avatar image
4

Answer by unigeek · Dec 28, 2014 at 10:55 AM

If you use Animator to control your animations you may set it to use unscaled time for its update mode. The same way, within the Update() method you may use Time.unscaledDeltaTime for your "pause independent" logic in place where you would normally use Time.deltaTime (e.g. you want to be able to move camera around while your game paused). I tested this with Unity 4.6 - works well and saves you from writing tons of custom stuff.

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 shieldgenerator7 · Dec 02, 2018 at 08:41 PM 0
Share

this should be the accepted answer

avatar image Owen-Reynolds shieldgenerator7 · Dec 02, 2018 at 10:59 PM 0
Share

We mostly go by votes here. It doesn't matter if a Q has an accepted answer, or which one it is. The person who asked the Q can "Accept" the one that helped them. That's good for 1-in-1. But Q's here are meant to help everyone - the OP's best answer may not be the one the helps everyone else. Also, this particular response was posted 11 months after the Q, so the asker was probably long gone by then.

avatar image
1

Answer by Owen-Reynolds · Feb 21, 2014 at 11:11 PM

If you have to set timescale to 0, you can hand-drive an animation by manually changing its time variable:

 void Update() {
   animation["bob"].time += 0.01f;

It won't be frame-rate independent (since you can't use Time.deltaTime,) but trial&error can probably get it close enough.

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 d3thdrug · Feb 23, 2014 at 06:47 AM 0
Share

hmm that can maybe work, I'll let you know

avatar image Veerababu.g · Nov 05, 2015 at 04:56 AM 0
Share

if it is a image sprite then. I mean after my player destroyed the whole game is paused.(am using Time.timeScale=0) i need to show a canvas image sprite .

it contains save me option.

how can i do this

thanks for reading

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

24 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

Related Questions

Particle system pauses when off-screen 2 Answers

Stop Whole game except one one object 1 Answer

Transition from 2D bone-based animation to ragdoll? 1 Answer

How do I fix this stupid jump animation not transitioning 1 Answer

Pausing an animation in a parent game object? 4 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