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.
Last updated