hi i need to know how can i make a script to deduct the maximum durability when hitting and then it will break up (disappear)?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Durability : MonoBehaviour
{
public float maxDurability = 100.0f; // max durability
public float curDurability; // current durability
public GameObject gameObject;
// Start is called before the first frame update
void Start()
{
curDurability = maxDurability;
}
// Update is called once per frame
public void HitSomething()
{
curDurability -= 5;
if (curDurability <= 0){
Destroy(gameObject);
}
}
}
this script doesn’t work for me what about it?