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 HHameline · Jun 07, 2011 at 07:11 PM · timeanimationstimescale

Time timeScale and Animations

Hello, I'm trying to create a simple pause menu, while the game is paused I set the Time.timeScale to zero, which pauses everything wonderfully. However I noticed that a few of my button animations are running incorrectly?

     // Pause Controller
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         // Paused, or unpaused
         pauseMenu.GetComponent<PauseMenuScript>().Display = !pauseMenu.GetComponent<PauseMenuScript>().Display;

         pauseMenu.SetActiveRecursively(pauseMenu.GetComponent<PauseMenuScript>().Display);

         if (pauseMenu.GetComponent<PauseMenuScript>().Display)
         {
             // Paused
             Time.timeScale = 0;
         }
         else
         {
             // Remove menu, and re-enable the players, laptimer, etc....
             Time.timeScale = 1;
         }

     }
     // End Pause Controller

That is the logic that pauses my game.

The script that handles the button animations looks like this:

     using UnityEngine;
     using System.Collections;

     public class btnAnim : MonoBehaviour 
     {
 
         public AnimationClip onAnim;

         void OnMouseEnter() {
             animation.AddClip(onAnim, "on");
                  animation["on"].speed = 1.0F;
             animation.Play("on");
         }
 
         void OnMouseExit() {
             animation["on"].speed = -1.0F;
             animation["on"].time = animation["on"].length;
             animation.Play("on");
         }
 
         void OnMouseUp() {
             gameObject.SendMessage("onClick", SendMessageOptions.DontRequireReceiver);
         }    
     }

This script takes the button it is attached to and makes it slowly appear brighter when it is moused over due to the animation I'm using. It works fine for all the other buttons through out the game perfectly until I display the pause menu when the Time.timeScale = 0. If I drag my pause menu prefab into a empty scene it works fine. So I was wondering if it was the Time.timeScale = 0 that's making my animation look like its running backwards or if it was something else entirely.

What I mean by backwards is on mouse over the first time nothing happens, and then when you leave the button it animates the mouse over animation and when you go back it animates the on mouse leave animation.

Thanks in advance, Hans

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
1
Best Answer

Answer by Anxo · Jun 07, 2011 at 07:21 PM

Your buttons are animated on frame basis. Updates and stuff is not effected by Time. It will continue to run your code. To solve this you can add Time to your button animations. So instead of moving it by 1, you can move it by 10*Time.deltaTime or so. That will make your button animation move relative to your game time.

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 HHameline · Jun 07, 2011 at 07:38 PM 0
Share

Thanks that fixed my animation problems :D greatly appreciated.

avatar image
3

Answer by Orrib · Jan 08, 2016 at 10:45 AM

The easiest solution is to go under the animator on your gameobject, then go under "Update Mode" and choose "Unscaled Time."This way you the animator isn't affected by timescale modification. This method saves a lot of time and effort, and is coding-free!

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 Fr0sZ · Jun 07, 2011 at 07:31 PM

You can also have a bool variable that checks if it pasued.

 if(!paused) //if not paused
 {
    //do stuff
 }
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Single Step (pause, resume), or externally clock game loop 0 Answers

Time.timeScale not working with Havok Physics 0 Answers

Problem changing TimeScale 1 Answer

'Time' does not contain a definition for 'timeScale' 1 Answer

Slow Time in Area 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