The Script I have bellow works for damage and health but the critical chance part isn’t working. I inserted an image as well to show that its showing up properly in the unity Inspector as well
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AttributesManager : MonoBehaviour
{
public int health;
public int attack;
public float critDamage = 1.5f;
public float critChance = 0.5f;
public void TakeDamage(int amount)
{
health -= amount;
Vector3 randomness = new Vector3(Random.Range(0f, 0.25f), Random.Range(0f, 0.25f), Random.Range(0f, 0.25f));
DamagePopUpGenerator.current.CreatePopUp(transform.position, amount.ToString(), Color.red);
if (health <= 0)
Destroy(gameObject); // Destroy the current object
}
public void DealDamage(GameObject target)
{
var atm = target.GetComponent<AttributesManager>();
if (atm != null)
{
float totalDamage = attack;
//Count RNG Chance
if(Random.Range(0f, 1f) < critChance)
{
totalDamage *= critDamage;
}
atm.TakeDamage((int)totalDamage);
}
}
}