Skip to content

Commit d5a0746

Browse files
committed
Invoke projectile destroyed callback OnDestroy
1 parent 68c45df commit d5a0746

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Assets/Scripts/Projectile.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ private void Awake()
3333
_collider = GetComponent<BoxCollider2D>();
3434
}
3535

36+
private void OnDestroy()
37+
{
38+
this.destroyed?.Invoke(this);
39+
}
40+
3641
private void Update()
3742
{
3843
// Move the projectile in the given direction by its speed
@@ -47,9 +52,7 @@ private void CheckCollision(Collider2D other)
4752

4853
// The projectile is destroyed when colliding with any object other than
4954
// a bunker or when it splats on a bunker
50-
if (bunker == null || bunker.CheckCollision(_collider, this.transform.position))
51-
{
52-
this.destroyed?.Invoke(this);
55+
if (bunker == null || bunker.CheckCollision(_collider, this.transform.position)) {
5356
Destroy(this.gameObject);
5457
}
5558
}

0 commit comments

Comments
 (0)