public static Character FromObject(GameObject g) { DamageHitbox d = g.GetComponent <DamageHitbox>(); if (d != null) { g = d.GetRootObject(); return(g.GetComponent <Character>()); } return(g.GetComponentInParent <Character>()); }
public static void Knockback(GameObject attackedObject, float force, Vector3 direction) { if (force != 0) // Checks if knockback needs to be applied { Rigidbody rb; DamageHitbox d = attackedObject.GetComponent <DamageHitbox>(); // Checks object hit for DamageHitbox script if (d != null) // If script is present, the object must be a DamageHitbox, so it checks its root object for a rigidbody component. { rb = d.GetRootObject().GetComponent <Rigidbody>(); } else { rb = attackedObject.GetComponent <Rigidbody>(); // If object is not a hitbox, look for rigidbody script in object. } if (rb != null) // If a rigidbody is found, apply knockback force. { rb.AddForce(direction * force, ForceMode.Impulse); } } }
public static Character FromHitbox(DamageHitbox d) { GameObject g = d.GetRootObject(); return(g.GetComponent <Character>()); }