I was programming this health code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class hurt : MonoBehaviour
{
public GameObject img;
public GameObject img1;
public GameObject img2;
int h = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
switch (h)
{
case 1:
Destroy(img);
break;
case 2:
Destroy(img1);
break;
case 3:
Destroy(img2);
break;
}
}
void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("e"))
{
h = h + 1;
}
else
{
h = h + 0;
}
}
}
This code deletes hearts when I touch the enemy.
but the order that the hearts delete is very inconsistent like sometimes it will delete the middle heart then last heart and not the first sometimes it will delete the first two but not the third. Then when I touch it again deletes the third why is this so inconsistent.