Example: Applying Damage with TakeHit
To interact with the shield, simply call TakeHit from your own script. Here`s an example from a bullet script:
private void OnCollisionEnter(Collision collision) {
var shield = collision.gameObject.GetComponent<ShieldController>();
if (shield != null) {
shield.TakeHit(collision, damage);
}
Destroy(gameObject);
}
This function checks if the object hit has a ShieldController, applies damage at the collision point, and then destroys the bullet.
You can extend this pattern for other weapon types (melee, area-of-effect, etc.) by calling TakeHit with the appropriate damage values.
Last updated