how to increase player health with a trigger event?

I am trying to make it so that when my player hits a certain collider or “power-up” but I can’t get it working.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PlayerScript : MonoBehaviour {

public int points = 0;
public const int maxhealth = 4;
public int currenthealth = maxhealth;
//public int evades;
public int NumofHearts = 4;

public Image[] hearts;
public Sprite fullheart;
public Sprite emptyheart;

PlayerScript player;
// Use this for initialization
void Start () {
    player = FindObjectOfType<PlayerScript>();
}

// Update is called once per frame

void Update () {
	for (int i = 0; i < hearts.Length; i++)
    {
        if(i < currenthealth)
        {
            hearts*.sprite = fullheart;*

}
else
{
hearts*.sprite = emptyheart;*
}
if(i < NumofHearts)
{
hearts*.enabled = true;*
}
else
{
hearts*.enabled = false;*
}
}
* }*

/*
public void Takedamage(int amount)
{
currenthealth -= amount;
if(currenthealth <= 0)
{
FindObjectOfType().EndGame();
currenthealth = 0;
Debug.Log(“Dead”);
}
}
*/
public void ApplyDamage()
{
currenthealth–;
if(currenthealth <= 0)
{
FindObjectOfType().EndGame();
}
}
/*
private void OnGUI()
{
GUI.Label(new Rect(15, 15, 200, 30), "Keys Collected : " + points);
}
*/
}
Here is my player script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Healing : PlayerScript {
public int heal = 1;
public void OnTriggerEnter()
{
currenthealth = maxhealth();
}

}
Here is the script I’m trying to make the health power-up, I would like to set it up where it only increases the player’s health when it’s less then the max health, and only by 1, but I’m fine with just getting it working where it completely heals the player if that’s easier to set up.

Might I ask why you have inherited Healing from PlayerScript?
Forgive me if I’m wrong, but it appears to me that you haven’t properly grasped the concept of inheritance.

Just to clarify - that Healing class shares all of the behaviour and properties of the PlayerScript class, plus the addition of an integer (heal) and a method (OnTriggerEnter).

If I had to guess, then it may be that Healing doesn’t actually exist as an instance in the program (i.e there’s no component of its type attached to an object), but you instead have used the PlayerScript as a component on your ‘character’ object, which does not implement OnTriggerEnter.

Alternatively, I would suggest that you ensure that your collider is set up properly to behave as a trigger.

On tip I can suggest is to utilise Debug.Log to ensure that lines of code are being reached by your program. For instance, you could use Debug.Log(“Trigger Enter called.”) inside of the OnTriggerEnter method.

By the way - you could also use ‘this’ in place of ‘FindObjectOfType();’ as ‘this’ refers to ‘this object’