- Home /
Powerup Issues (Heart Point Addition and Infinite Double Point Can't Stop When Get Another Powerup While Having Powerup That Doesn't Stop Yet)
Hello everyone, right now i'm making 2d endless runner game, so i already have the codes that whenever powerup collide to player it will going to add heart point and double score point for 5 seconds, and the powerup won't add another point if they collide again with another powerup while powerup active But the problems are: 1. Heart works fine with addition heart point, but sometimes while powerup active and collides to the enemy, the player heart doesn't decrease, but sometimes it does. 2. While having powerup and get another powerup while the previous doesn't finish yet, the double point score won't stop eventhough the 5 second powerup length already finished. this is the power up manager code that i have, thank you so much if you guys can help me with this issues..`using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PowerupManager : MonoBehaviour {
private bool doublePoints;
private bool heartPlus;
public bool powerupActive;
public float powerupLengthCounter;
private ScoreManager theScoreManager;
private PlayerController thePlayer;
private float normalPointPerSecond;
private int normalHeart;
// Use this for initialization
void Start () {
theScoreManager = FindObjectOfType<ScoreManager> ();
thePlayer = FindObjectOfType<PlayerController> ();
}
// Update is called once per frame
void Update () {
if (powerupActive)
{
powerupLengthCounter -= Time.deltaTime;
if (doublePoints && normalPointPerSecond<12) {
theScoreManager.pointsPerSecond = normalPointPerSecond * 3f;
}
if (heartPlus && normalHeart<3) {
thePlayer.health = normalHeart + 1;
}
if (powerupLengthCounter <= 0) {
theScoreManager.pointsPerSecond = normalPointPerSecond;
powerupActive = false;
}
}
}
public void ActivatePowerup (bool pointsPowerupManager, bool heartPowerupManager, float time )
{
doublePoints = pointsPowerupManager;
heartPlus = heartPowerupManager;
powerupLengthCounter = time;
normalPointPerSecond = theScoreManager.pointsPerSecond;
normalHeart = thePlayer.health;
powerupActive = true;
}
}`
Answer by FoodLover195 · Oct 21, 2018 at 03:14 AM
Hey there @dimasapry
I can't tell you what's wrong with your score counter. I feel like it's likely due to something outside the script, however the heart problem is because you have it in an Update loop. Instead you should keep your powerup effects in the ActivatePowerup function and just use the update function to adjust your timer and reset everything once it's over.
Thank you so muchh you save my problem with the hearts perfectly! @FoodLover195
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Power up not working 1 Answer
Distribute terrain in zones 3 Answers
I can't give damage with these scripts 2 Answers
Second Coroutine isn't working Unity 1 Answer