I’ve just started using unity and need some help with registering collisions from a bullet and affecting the player’s health. Here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHurt : MonoBehaviour
{
public int maxHealth = 100;
public int currentHealth;
// Start is called before the first frame update
private void Start()
{
currentHealth = maxHealth;
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Bullet")
{
void kill();
}
}
void kill()
{
if (currentHealth != 0)
{
currentHealth -= 10;
}
if (currentHealth <= 0)
{
Destroy(gameObject);
}
}
}