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 cr8iv · Jan 21, 2017 at 06:52 AM · 3dcontrolslowmotion

Im trying to get a slow motion system working

I've been trying to make a slow motion system but it doesnt work this is the code that i used:

 bool ctrlDown = false;

 // Use this for initialization
 void Start()
 {

 }

 // Update is called once per frame
 void Update()
 {
 if (Input.GetKeyDown(KeyCode.LeftControl)) {
         ctrlDown = true;
 } else {
         ctrlDown = false;
 }
 if (ctrlDown == true) {
     Time.timeScale = 0.1f;
 } else {
     Time.timeScale = 1f;
     }
 }

im trying to make it so when you press control it goes into slow motion

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
0

Answer by shellash · Jan 21, 2017 at 09:54 AM

Hello!

GetKeyDown method returns true only in the first frame of pressing button. If you keep button pressed, it returns false.

Try using GetKey instead.

Hope this helps.

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 cr8iv · Jan 22, 2017 at 03:20 AM 0
Share

thank you, ive been trying to get this working for ages

avatar image
0

Answer by Firechicken · Jan 21, 2017 at 02:37 PM

You used GetKeyDown, but GetKeyDown only triggers an event once even if you hold it down, so you have to replace it with GetKey

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 Loui_Studios · Jan 21, 2017 at 03:46 PM

Here are shortened versions of your code. If you want time to slow only while you are pressing control, use Input.GetKey() this:

  void Update()  {
      // Slow time while control is pressed.
      if (Input.GetKey(KeyCode.LeftControl))
          Time.timeScale = 0.1f;
      else
          Time.timeScale = 1f;
  }

If you wanted to toggle the slow motion with control, then use Input.GetKeyDown() like this:

  bool slowTime = false;

  void Update()  {
      // When CTRL is pressed, set "slowTime" to the opposite of it's current value.
      if (Input.GetKeyDown(KeyCode.LeftControl))
          slowTime = !slowTime;
      if (slowTime)
          Time.timeScale = 0.1f;
      else
          Time.timeScale = 1;

  }

The reason why your code wasn't working before was because you were using Input.GetKeyDown(), which will only detect the key press for the frame that the key was pushed down.

Input.GetKey() detects continuously so time will slow while CTRL is pressed.


I hope I helped you understand what went wrong and how I fixed it!

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

How should I control a 'rake' that pushes objects around a table? 2 Answers

Player Control Script Makes Movement Buggy? 1 Answer

The best way to control speed of the animation together with audio sound that both must sync 0 Answers

Making a hand move with the mouse 1 Answer


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