How to I start my jump boost power up timer when player collides with power up?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class JumpPowerUp : MonoBehaviour {
public GameObject PowerUp;
public GameObject RunningMan;
private float timer = 0;
float jumper;
void OnTriggerEnter2D(){
RunningMan.GetComponent<RunningManMov> ().jump = 9;
Destroy(PowerUp);
}
void OnTriggerExit2D(){
timer += 1
}
void Update(){
jumper = RunningMan.GetComponent<RunningManMov> ().jump;
if (timer > 5) {
RunningMan.GetComponent<RunningManMov> ().jump = 6;
}
}
}
Comment
Answer by TCROC · Jun 22, 2016 at 04:06 PM
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class JumpPowerUp : MonoBehaviour {
public GameObject PowerUp;
public GameObject RunningMan;
private float timeExited = 0;
private float timeForPowerUpToLast = 5;
float jumper;
void OnTriggerEnter2D(){
RunningMan.GetComponent<RunningManMov> ().jump = 9;
Destroy(PowerUp);
}
void OnTriggerExit2D(){
// Get access to the current time
timeExited = Time.time;
}
void Update(){
jumper = RunningMan.GetComponent<RunningManMov> ().jump;
// A timer that lasts for five seconds
// Current time subtracted by the time you exited the trigger
if (Mathf.Abs (Time.time - timeExited) >= timeForPowerUpToLast) {
RunningMan.GetComponent<RunningManMov> ().jump = 6;
}
}
}
Your answer
Follow this Question
Related Questions
I need my timer to only start after it hits a trigger. Please help! 0 Answers
Trigger a Timer 2 Answers
Getting a timer to go to 0 1 Answer
Capture Zone Timer 0 Answers