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:
- 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.
- 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;
}
}`