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 /
  • Help Room /
avatar image
0
Question by El-Deiablo · May 15, 2016 at 08:58 PM · triggerslowmotionpower-up

Slow Motion Effect on Trigger

I am so close to figuring this out! I am trying to make a slow motion powerup using Time.timeScale, but I am running into several issues. I have watched many tutorials and searched unityanswers for a solution, but almost all the answers discuss initializing the effect on mouseclick down.

Issues:

The Player is unable to collide with the object even though both objects have 2D colliders (trigger is active on powerup and NOT Player). Therefore the effect never occurs. I also want to destroy the powerup when it is picked up.

Here is my code:

Code1:

 using UnityEngine;
 using System.Collections;
 
 public class PowerUpManager : MonoBehaviour {
 
     private  bool doublePoints;
     private  bool slowMo;
     private  bool fastMo;
 
     private  bool powerUpActive;
     private float powerUpLengthCounter;
 
     private ScoreManager theScoreManager;
 
     private float score;
 
     private float slowDown = Time.timeScale ;
 
 
 
     // Use this for initialization
     void Start () {
         theScoreManager = FindObjectOfType <ScoreManager > ();
     }
     
     // Update is called once per frame
     void Update () {
 
         if (powerUpActive) {
 
             powerUpLengthCounter -= Time.deltaTime;
 
             if (slowMo) {
 
                 slowDown  = 0.5f;
                 
             }
         }
 
         if (powerUpLengthCounter <= 0) {
 
             slowDown  = 1f;
             powerUpActive = false;
 
         }
     
     }
 
     public void ActivatePowerUpSlowMotion(bool slow, float time, float effect){
 
         slowMo = slow;
         powerUpLengthCounter = time ;
         slowDown = effect;
 
         powerUpActive = true;
 
     }
 }

Code 2:

 using UnityEngine;
 using System.Collections;
 
 public class PowerUp : MonoBehaviour {
 
     public bool doublePoints;
     public bool slow;
     public bool fast;
     public float speed=Time .timeScale ;
 
     public float powerUpLength;
 
     private PowerUpManager thePowerUpManager;
 
     // Use this for initialization
     void Start () {
         thePowerUpManager = FindObjectOfType <PowerUpManager > ();
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnTriggerEnter2D(Collider2D other){
 
         if (other.tag == "Player") {
             thePowerUpManager.ActivatePowerUpSlowMotion (slow, powerUpLength,speed ); 
         }
 
         gameObject.SetActive (false);
     }
 }

Your help is appreciated!

Comment
Add comment · Show 4
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 Le-Pampelmuse · May 16, 2016 at 03:25 AM 1
Share

What have you tried already?

Did you check if the player object has the "Player" tag assigned? Does the ActivatePowerUpSlowmotion get triggered? Add a print("x"); in the OnTriggerEntered function to check that.

By the way, you are never changing the timescale, only the value of slowDown.

So even if everything works, and slowDown is set to 0.5f, it doesn't do anything.

avatar image El-Deiablo · May 16, 2016 at 05:07 PM 0
Share

What would you suggest doing?

avatar image Le-Pampelmuse El-Deiablo · May 18, 2016 at 08:21 PM 1
Share

Answering the questions I asked.

And also adding timeScale = SlowDown into the Update function of Code 1, so it get's changed to what it should be.

avatar image El-Deiablo Le-Pampelmuse · May 18, 2016 at 09:09 PM 0
Share

Thanks for getting back to me. The objects are now triggering and the desired effect occurs, but the powerUpLength is not working. When one of the effects is triggered it does not stop. Also I want to keep the player animation speed normal. I have done some research and was trying to use Time.unscaledDeltaTime, but have been unable to make it work.

Here's what I've tried:

 using UnityEngine;
 using System.Collections;
 
 public class PowerUp$$anonymous$$anager : $$anonymous$$onoBehaviour {
 
     private  bool doublePoints;
     private  bool slow$$anonymous$$o;
     private  bool fast$$anonymous$$o;
 
     private  bool powerUpActive;
     private float powerUpLengthCounter;
 
     private Score$$anonymous$$anager theScore$$anonymous$$anager;
 
     private float score;
 
     private float slowDown = Time.timeScale ;
     //private float slowDown = Time.unscaledDeltaTime ;
 
 
 
     // Use this for initialization
     void Start () {
         theScore$$anonymous$$anager = FindObjectOfType <Score$$anonymous$$anager > ();
     }
     
     // Update is called once per frame
     void Update () {
 
         if (powerUpActive) {
 
             powerUpLengthCounter -= Time.unscaledDeltaTime;
 
             if (slow$$anonymous$$o) {
 
                 //Time.unscaledDeltaTime = slowDown;
                 Time.timeScale = slowDown;
                 slowDown  = 0.5f;
 
                 
             }
         }
 
         if (powerUpLengthCounter <= 0) {
 
             //Time.unscaledDeltaTime = slowDown;
             Time.timeScale = slowDown;
             slowDown = 1f;
             powerUpActive = false;
 
         }
     
     }
 
     public void ActivatePowerUpSlow$$anonymous$$otion(bool slow, float time, float effect){
 
         slow$$anonymous$$o = slow;
         powerUpLengthCounter = time ;
         slowDown = effect;
 
         powerUpActive = true;
 
     }
 }

0 Replies

· Add your reply
  • Sort: 

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

Slow Motion PowerUp 0 Answers

my counter wont change from 0 help 1 Answer

Need help with bone animation and trigger code. 0 Answers

OnTriggerEvent doesn't work 1 Answer

[SOLVED] OnTriggerEnter doesn't work? 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