Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 coolwithpie · Mar 05, 2014 at 10:47 PM · javascripttime.timescaleslowmotion

Slow and Fast motion?

I am trying to speed up and slow down time using time.timescale in unityscript. what happens is the fast motion code never runs, and I cant set the time back to normal. Any help with the code?

  public var slow : boolean = false;
  public var fast : boolean = false;
 function Update () {
  if(Input.GetButtonUp("Slomo")){
   if(!slow){
    Time.timeScale = .5;
    slow=true;
   }else{
    if(Input.GetButtonUp("Fast")){
   if(!fast){
    Time.timeScale = 2;
    fast=true;
   }else{
    Time.timeScale = 1;
    slow=false;
    fast=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
1

Answer by xt-xylophone · Mar 06, 2014 at 04:13 AM

Your if statements are all over the place. This might be easier to read:

 public var slow : boolean = false;
 public var fast : boolean = false;
 
 function Update () {
     if(Input.GetButtonUp("Slomo")){
         if(!slow){
             Time.timeScale = .5;
             slow=true;
         }else{
             if(Input.GetButtonUp("Fast")){
                 if(!fast){
                     Time.timeScale = 2;
                     fast=true;
                 }else{
                     Time.timeScale = 1;
                     slow=false;
                     fast=false;
                 }
             }
         }
     }
 }

So! Lets sort this out. What its currently doing is: if you release the Slomo key, it sets it to slowmo if it was not already slowmo. If it WAS slowmo and you just released the Fast key(which you probably never can do in the same fame) it will do the same for fastmode.

Do you want it to be a key you hold down for slowmo? Or 2 buttons to activate and deactivate, which is kind of a silly option. May as well be one button to turn it on and off.

Im gonna assume you want to hold down a button that makes it slowmo. Which is the simplest option.

Try this:

 if(Input.GetButton("Slomo")){
     slow = true;
     Time.timeScale = 0.5;
 } else {
     slow = false;
     Time.timeScale = 1;
 }

You dont need the fast boolean if you have a slow one since they are always opposites.

What this code is doing essentially is; While you are holding down the Slomo key, it will be slow, else it will not be slow.

Hope this helps! You need a lot more practice!

Oh! And have you actually set up and Input button called "Slomo" in the editor? This will never work if you haven't.

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 coolwithpie · Mar 06, 2014 at 08:37 PM 0
Share

yeah I do. I am really new. Anyway that was helpful but i didnt explain myself well. I want a key that lets me double the speed of everything, and a key that lets me halve it. The fast variable was the double speed, and slow variable was the half speed.

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

21 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

Related Questions

How to get a smoother slow motion 0 Answers

Time.timeScale is laggy 2 Answers

Time.timeScale is Having a Strange Effect on Physics 1 Answer

Time.timeScale not working 1 Answer

Manual Compilation of UnityScript / JavaScript 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