Health System

my health system isn t working and i don t know what to do

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

public class playerHealth : MonoBehaviour
public float fullHealth;

float currentHealth;

// Start is called before the first frame update
void Start()
    currentHealth = fullHealth;

// Update is called once per frame
void Update()
    if (currentHealth -= 0);


Firs of all you need to make if currentHealth <= 0.
And if you can please send the full script so i can see the other problems.

The errors come from the inside of the Update.
For the first error, at the if (currentHealth -= 0); you have a logic and syntax error, I tell you in order for you to understand how if statements work:

  • The -=its a Subtract AND assignment operator, it subtracts right operand from the left operand and assign the result to left operand. If what you are trying to do is check if the currentHealth is less or equal to 0, then the operation would be currentHealth <= 0.
  • The if statement syntax normally shouldn’t have a semicolon ( ; ) at the end, its normal syntax would be:


if ( <condition> )
    //If the condition is true, then make what is inside the { }.
  • For last, the second error that you are getting it’s because inside the Destroy()you are referring to your gameObject wrong, it can be confussing but let me explain: When you use GameObject with G you are talking about the GameObject type, and when you use gameObject with g you are talking about the actual Game Object you are using, so it should be Destroy (gameObject).

Taking all this fixes, your if statement should look like:

if (currentHealth <= 0)
    Destroy (gameObject);

In order to help you understand better the logic and syntax of C#, I recommend you to check out the C# tutorial at, which I’ll leave you here: C# Tutorial
Hope that helps you out!