Hi! So I’m writing a script on an enemy to detect a hit from a damaging ability and I want to be able to decide how much damage the ability will cause with a float on a script attached to the ability. I want to make this more accessible and changeable for future damaging abilities I add. So, on the damaging object, is a script named damageAmount which contains nothing important except the two floats:
public float Damage;
public float DPS;
I want to be able to use this script on all of my future damaging abilities, adjusting the numbers for each in the future.
Now, the script on the enemy is as follows:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DummyHealth : MonoBehaviour
{
public float Health;
public float DummyDamagePerSecond;
public float DummyDamageTaken;
// Update is called once per frame
void Update()
{
/// DummyDamageTaken = col.gameObject.GetComponent<damageAmount>().Damage; <- I know this is incorrect
}
void OnTriggerStay2D(Collider2D col)
{
if (col.gameObject.tag == "DamagingEnemies")
{
artCoroutine(InflictDamage());
}
}
IEnumerator InflictDamage()
{
Debug.Log("DamageInflicting...");
Health -= DummyDamageTaken;
Debug.Log("Damage Inflicted");
yield return new WaitForSeconds(DummyDamagePerSecond);
}
}
The part I’m having trouble with is
/// DummyDamageTaken = col.gameObject.GetComponent<damageAmount>().Damage;
My goal is to assign the variable ‘DummyDamageTaken’ to the number that is attached to the Damage variable on the script on the colliding object.
Again, I would like to have the same script on multiple different objects, and then the enemy will identify which object is hitting so it can pull the number from that specific script.
I’m sorry if this is so confusing and complicated, I’m fairly new to programming and am doing my best to learn. If you need me to clarify, feel free to ask!