so...my issue is at healthText.text = "health: " + Health my console says object reference is not set to an instance of the object. Sorry for the terrible code but i'm into coding for only 2.5 weeks so, don't stick your eyes out pls.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class PlayerDED : MonoBehaviour
{
public int Health = 100;
public int damage = 2;
public Text healthText;
public bool AlreadyTook = false;
// Start is called before the first frame update
void Update(){
Die();
healthText.text = "Health : " + Health.ToString();
}
void TakeDamage(){
Health -= damage;
}
public void Die(){
if(Health <= 0){
Debug.Log("SceneManager.LoadScene(Dead);)");
}
}
void OnCollisionEnter2D(Collision2D col ){
if(col.collider.tag == "Enemy" && AlreadyTook == false){
AlreadyTook = true;
TakeDamage();
}
}
void OnCollisionExit2D(Collision2D col){
if(col.collider.tag == "Enemy"){
AlreadyTook = false;
}
}
}