Hello!
I have a 2d collision script that is supposed to acknowledge collision to the player from a certain object (sword) and subtract health from the players total health. Finally it turns on a box that says, “You Died.” when the player gets equal to or below 0.
However this isn’t working/registering, and I tried to use the debug.log to help but to no prevail.
Any Help Would be Greatly Appreciated!!!
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class healthcollison : MonoBehaviour
{
public int health = 100;
public RawImage deathbox;
// Start is called before the first frame update
void Start()
{
deathbox.enabled = false;
}
// Update is called once per frame
void Update()
{
if (0 >= health)
deathbox.enabled = true;
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.name == "sword")
{
health -= 35;
Debug.Log(health);
}
}
}
