So I'm trying to create a method that takes the damage. This is also attached to another program so that it can read that one as well. basically, this method is called in whenever the other program is pulled. The issue is with this one though, where the error says "Object reference is required..." for "HealthBar" "CurrentHealth" and "MaxHealth". How can I make it so this is no longer an error?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HealthBarScript : MonoBehaviour
{
public Image HealthBar;
public float CurrentHealth;
public float MaxHealth = 100f;
int Damage = 10;
PlayerController_Script Player;
private void Start()
{
HealthBar = GetComponent<Image>();
CurrentHealth = 100f;
}
public static void TakeDamage(int Damage)
{
CurrentHealth -= Damage;
HealthBar.fillAmount = CurrentHealth/MaxHealth;
}
}