I want to assign damage, mana drain, etc. etc. on impact to each object. So for instance, the player collides with a creature, and receives a “damage pack” from the creature object on collision that contains all of the values. Currently I’m using structs which I’m assigning in the creature scripts. then doing the following on collision in the players script:
private void OnTriggerEnter(Collider other) {
if (other.gameObject.CompareTag("Life PU") || other.gameObject.CompareTag("Mana PU"))
{
PickupScript otherScript = other.gameObject.GetComponent<PickupScript>();
playerLife += otherScript.dmgPack.life;
playerMana += otherScript.dmgPack.mana;
playerLight += otherScript.dmgPack.light;
Destroy(other.gameObject);
UpdateResources();
}
}
I’d like to do something more like:
playerLife += other.dmgPack.life;
etc.
Without having to specify a variable and specifically assign it the script attached to the object. Isn’t there a way to add structs or classes directly to gameObjects? What’s the best way to pass variables such as damage etc. between game objects/scripts?