Hello, I’m having this weird problem where my main health script doesn’t want to pick up a bool from another script. Or at least I think that’s the problem. Basically, I have this health pickup that detects when the player is colliding with it. And when it does, it sets a bool in itself to true for a few frames. Then it deletes itself. The global player health script is supposed to take the variable from that script and use it to add health. But it doesn’t do anything at all when the bool is set to true. So uh, I guess I’ll put some code below.
//This is the health pickup segment in the main player health script
#region Health Pickups
//Initializing Variables
bool hp1 = GameObject.Find("Heart").GetComponent<HealthPickup>().Health;
//Applying Health
if (hp1 == true)
{
Health += 1;
Debug.Log("I got health!");
}
#endregion
//The whole Health Pickup Script
using UnityEngine;
using System.Collections;
public class HealthPickup : MonoBehaviour {
bool isFull = false;
public bool Health = false;
float HP;
float maxHP;
void Update () {
HP = GameObject.Find("Player").GetComponent<PlayerHealth>().Health;
maxHP = GameObject.Find("Player").GetComponent<PlayerHealth>().maxHealth;
if (HP == maxHP)
{
isFull = true;
}
else { isFull = false; }
}
void OnTriggerEnter2D(Collider2D trig)
{
if ((trig.gameObject.tag == "Player") && (isFull == false))
{
Health = true;
Destroy(this.gameObject, 0.1f);
Debug.Log("I am health!");
}
}
}
If you need me to, I can post the entire player health script. Thanks in advanced!