Problems with power up
I'm trying to make a shield power up. I got it all working but it seems that my player is still losing health.
Here's my player health script: using UnityEngine; using UnityEngine.UI; using System.Collections;
public class PlayerHealth : MonoBehaviour {
public float curHealth;
public float maxHealth;
public float amount;
public GameObject playerExplosion;
public GameObject playerHit;
public Text healthText;
private Done_GameController gameController;
// Use this for initialization
void Start ()
{
healthText.text = "Health: " + curHealth;
curHealth = 3;
maxHealth = 3;
amount = 1;
curHealth = maxHealth;
GameObject gameControllerObject = GameObject.FindGameObjectWithTag ("GameController");
if (gameControllerObject != null)
{
gameController = gameControllerObject.GetComponent <Done_GameController>();
}
if (gameController == null)
{
Debug.Log ("Cannot find 'GameController' script");
}
}
void Update()
{
}
void OnTriggerEnter (Collider other)
{
if (other.tag == "Enemy")
{
if (curHealth <= maxHealth)
{
Instantiate(playerHit, other.transform.position, other.transform.rotation);
curHealth -= amount;
healthText.text = "Health: " + curHealth;
}
if (curHealth <= 0)
{
curHealth = 0;
Dead();
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
}
}
}
public void Dead()
{
gameController.GameOver();
Destroy(gameObject);
}
}
here's my shield script:
using UnityEngine;
using System.Collections;
public class Shield : MonoBehaviour {
public GameObject shield;
public bool forceActive = false;
public void ActivateShield()
{
StartCoroutine (CreateForceField());
}
IEnumerator CreateForceField ()
{
if (forceActive)
{
yield break;
}
forceActive = true;
shield.SetActive (true);
yield return new WaitForSeconds (5.0f);
shield.SetActive (false);
forceActive = false;
}
}
and here's my shieldUPS if the player collide, he will have shield
using UnityEngine;
using System.Collections;
public class ShieldUPS : MonoBehaviour {
public Shield shield;
void Start () {
shield = shield.GetComponentInChildren<Shield>();
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "ShieldUPS")
{
shield.ActivateShield();
Destroy (other.gameObject);
}
}
}
I also drag the shield to the player so the shield will follow the player, if i remove the shield from the player object, the shield works. Any help would be appreciate.
Comment
Your answer
Follow this Question
Related Questions
Need help with a random item selector similar to Mario Karts item system 1 Answer
faulty powerups 0 Answers
Parent Problem 1 Answer
Can sb help? Artifact with terrain or another objects 0 Answers