- Home /
magnetic Powerup Timer Problem
Hi there. I need help. I have one magnetic powerup in game after picking it up...player will start attracting coins ... And after sometime efffect will go off.Its all working fine. But in one scene it works only for first magnetic powerup..not the next one. Please help.
Here is my script which is put on coin..there is one bool in script which is attached to magnetic powerup icon(to be picked in game).this bool becomes true when player collides.bool is magneticeffect
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class Coins_Magnet : MonoBehaviour {
public GameObject char2d;
public static int PlayerScore = 0;
int ScoreInc = 10;
public GameObject Coin;
public AudioClip CoinPickupSound;
public static float timeLimit = 10.0f;
void Start(){
}
void Awake()
{
}
void Update ()
{
if(Vector3.Distance(transform.position, char2d.transform.position) < 5 && MagnetPU.PUEffect == true && timeLimit > 0){
timeLimit -=Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, char2d.transform.position, Time.deltaTime *11);
}
if (timeLimit <0 ){
MagnetPU.PUEffect = false;
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
PlayerScore+=ScoreInc;
Destroy(this.gameObject);
if (Mute.clips == true){
AudioSource.PlayClipAtPoint (CoinPickupSound, transform.position);
}
}
}
void OnDisable(){
} }
I know the problem is second magnet is not getting more timeLimit. i need to add else condition..but its not working..getting more bugs
After a certain amount of time try suspending all operations on one magnet and reseting the timer and use in another magnet and so on.
And they are identical? The first and second powerups?
thanks all for ur response... Yes meat5000 both powerups are identical.i have checked it many times. Nimish I am having problem with resetting the timer. Because else is not working. This is the only part remaining in my game. I am so frustrated.
Answer by Tarondar · Feb 09, 2015 at 04:12 PM
Hi,
I think it could solve the problem if you change the code like this:
if (timeLimit <0 ){
MagnetPU.PUEffect = false;
timeLimit = 10.0f; // this line resets the timeLimit instantly when the effect ends
}
I think the timer should reset when timeLimit will be 0f.
Tarondar..thank u so much man....I was so stupid not to get that. Thanks a lot man.
Your answer
Follow this Question
Related Questions
Trying to Create a Powerup that lasts a certain amount of time 1 Answer
Deactivating a power up script after a certain amount of time 1 Answer
How to make a loop for PowerUps/Bonus 2 Answers
Powerup Timer not Working 3 Answers
Bug? And any way to do something for 5 seconds when shift is held? 1 Answer