From e4c89eb23f5d14a52ea1bc46033f0bbcd4eb39b3 Mon Sep 17 00:00:00 2001 From: Maximilian Wagner Date: Mon, 19 Jun 2023 11:03:08 +0200 Subject: [PATCH] =?UTF-8?q?=C3=84nderung=20an=20KitchenGun=20um=20Collider?= =?UTF-8?q?=20nutzen=20zu=20k=C3=B6nnen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/AssetsFORELLE/Script/KitchenGun.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Assets/AssetsFORELLE/Script/KitchenGun.cs b/Assets/AssetsFORELLE/Script/KitchenGun.cs index 01ec075..8ab1a6a 100644 --- a/Assets/AssetsFORELLE/Script/KitchenGun.cs +++ b/Assets/AssetsFORELLE/Script/KitchenGun.cs @@ -10,6 +10,8 @@ public class KitchenGun : MonoBehaviour public float shotIntervalSeconds = 1f; // Time alive for the projectiles public float shotAliveSeconds = 1f; + // Time until collider gets enabled + public float colliderDisabledSeconds = .2f; // Speed of projectiles public Vector2 shotSpeed = new Vector2(1f, 0f); // Smallest step size for shot speed @@ -41,6 +43,7 @@ public class KitchenGun : MonoBehaviour GameObject projectile = Instantiate(projectilePrefab, position, t.rotation); + // determine correct force vector Vector2 force = shotSpeed; if (t.localScale.x < 0) { @@ -49,8 +52,11 @@ public class KitchenGun : MonoBehaviour force *= shotSpeedStepSize; // add force to projectile - Rigidbody2D pBody = projectile.GetComponent(); - pBody.AddRelativeForce(force); + projectile.GetComponent().AddRelativeForce(force); + + // wait until enabling collider + yield return new WaitForSeconds(colliderDisabledSeconds); + projectile.GetComponent().enabled = true; // wait given time before destroying yield return new WaitForSeconds(shotAliveSeconds);