From 0865da787068d552445f07a2bce91d4dee70217d Mon Sep 17 00:00:00 2001 From: ProtoSharkk Date: Sun, 27 Oct 2024 19:11:47 -0700 Subject: [PATCH] Destroy gun when out of view --- Assets/Enemy/Gun.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Assets/Enemy/Gun.cs b/Assets/Enemy/Gun.cs index 80f008b..a1a0bf0 100644 --- a/Assets/Enemy/Gun.cs +++ b/Assets/Enemy/Gun.cs @@ -13,5 +13,9 @@ public class Gun : MonoBehaviour void Update() { transform.Rotate(new Vector3 (0, 0, Time.deltaTime * 1000)); + if (Vector3.Distance( + transform.position, + GameObject.FindGameObjectWithTag("Player").transform.position + ) > 20) Destroy(gameObject); } }