Änderung an KitchenGun um Collider nutzen zu können
This commit is contained in:
parent
294b920f8a
commit
e4c89eb23f
@ -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<Rigidbody2D>();
|
||||
pBody.AddRelativeForce(force);
|
||||
projectile.GetComponent<Rigidbody2D>().AddRelativeForce(force);
|
||||
|
||||
// wait until enabling collider
|
||||
yield return new WaitForSeconds(colliderDisabledSeconds);
|
||||
projectile.GetComponent<Collider2D>().enabled = true;
|
||||
|
||||
// wait given time before destroying
|
||||
yield return new WaitForSeconds(shotAliveSeconds);
|
||||
|
Loading…
x
Reference in New Issue
Block a user