Hi, I am doing some health icons on the screen as a canvas element. I’ve made a button and made a script for it. When the Player will find a FirstAid the button appear on the screen. Now, when his health is low, I press the FirstAid icon and the health should add extra points. But it doesn’t work. Can you tell me what is wrong in the code, or maybe I need to select appropriate function i button OnClick?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HealthInjection : MonoBehaviour {
PlayerController playerScript;
GameObject Player;
public GameObject firstaid;
void Awake () {
Player = GameObject.Find ("Player");
playerScript = Player.GetComponent<PlayerController> ();
}
void OnClick()
{
playerScript.health += 100.0f;
firstaid.SetActive (false);
}
void Update () {
if (playerScript.health > 100) playerScript.health = 100;
}
private GameObject player;
}