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);