Slow Down Powerup Help
I have been doing days of research trying to figure out how to set up my powerups and have had little luck! I know I have to use Time.timeScale and set that to a number less than one. I am able to get the slow down effect on trigger, but the gameObject does not destroy and the effect is continuous because I am unsure how to set up a timer in my script. Also the I want the player to remain at the normal speed (I've read something about multiplying the slow down speed of the player by a number in order to bring the speed back up to one). I have also read that a normal timer will be affected by the slow down and you must use an alternate timer. I want to do a speed up power up as well. If I can just figure out 1 of these powerups the rest shouldn't be so difficult. Any help or references would be appreciated.
Here's my code:
using UnityEngine;
using System.Collections;
using UnityEngine .Audio ;
using UnityEngine .SceneManagement ;
void Start(){
}
void update(){
Die();
}
public void OnTriggerEnter2D(Collider2D other){
if (other.tag == "Slow Down Clock") {
GameObject sound = new GameObject();
sound.transform.position = transform.position;
AudioSource audioSource = sound.AddComponent<AudioSource>();
audioSource.clip = slowDown ;
audioSource.Play();
Time.timeScale = 0.5f;
Destroy (sound, slowDown.length);
Destroy (other.gameObject);
}
}
public void Die(){
if (ScoreManager.TKOCount > 2) {
GameObject sound = new GameObject();
sound.transform.position = transform.position;
int randomClip = Random.Range (0, knockOut .Length);
AudioSource audioSource = sound.AddComponent<AudioSource>();
audioSource.clip = knockOut [randomClip ];
audioSource.Play();
Destroy (GameObject.FindGameObjectWithTag ("Player"));
Destroy (sound, knockOut [randomClip ].length );
SceneManager.LoadScene ("GameOver Scene");
}
if (health.CurrentValue <=0) {
GameObject sound = new GameObject();
sound.transform.position = transform.position;
int randomClip = Random.Range (0, knockOut .Length);
AudioSource audioSource = sound.AddComponent<AudioSource>();
audioSource.clip = knockOut [randomClip ];
audioSource.Play();
Destroy (GameObject .FindGameObjectWithTag ("Player"));
Destroy (sound, knockOut [randomClip ].length );
SceneManager.LoadScene ("GameOver Scene");
}
}
}
Your answer
Follow this Question
Related Questions
PowerUp timer not working when altering timeScale 0 Answers
Why is my animation being started, but is not actually playing? 1 Answer
Farming game Time management 0 Answers
How to slow down a ball in a tennis game ? 0 Answers
2D Power up script not working 0 Answers