Ä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;
|
public float shotIntervalSeconds = 1f;
|
||||||
// Time alive for the projectiles
|
// Time alive for the projectiles
|
||||||
public float shotAliveSeconds = 1f;
|
public float shotAliveSeconds = 1f;
|
||||||
|
// Time until collider gets enabled
|
||||||
|
public float colliderDisabledSeconds = .2f;
|
||||||
// Speed of projectiles
|
// Speed of projectiles
|
||||||
public Vector2 shotSpeed = new Vector2(1f, 0f);
|
public Vector2 shotSpeed = new Vector2(1f, 0f);
|
||||||
// Smallest step size for shot speed
|
// Smallest step size for shot speed
|
||||||
@ -41,6 +43,7 @@ public class KitchenGun : MonoBehaviour
|
|||||||
GameObject projectile = Instantiate(projectilePrefab,
|
GameObject projectile = Instantiate(projectilePrefab,
|
||||||
position,
|
position,
|
||||||
t.rotation);
|
t.rotation);
|
||||||
|
|
||||||
// determine correct force vector
|
// determine correct force vector
|
||||||
Vector2 force = shotSpeed;
|
Vector2 force = shotSpeed;
|
||||||
if (t.localScale.x < 0) {
|
if (t.localScale.x < 0) {
|
||||||
@ -49,8 +52,11 @@ public class KitchenGun : MonoBehaviour
|
|||||||
force *= shotSpeedStepSize;
|
force *= shotSpeedStepSize;
|
||||||
|
|
||||||
// add force to projectile
|
// add force to projectile
|
||||||
Rigidbody2D pBody = projectile.GetComponent<Rigidbody2D>();
|
projectile.GetComponent<Rigidbody2D>().AddRelativeForce(force);
|
||||||
pBody.AddRelativeForce(force);
|
|
||||||
|
// wait until enabling collider
|
||||||
|
yield return new WaitForSeconds(colliderDisabledSeconds);
|
||||||
|
projectile.GetComponent<Collider2D>().enabled = true;
|
||||||
|
|
||||||
// wait given time before destroying
|
// wait given time before destroying
|
||||||
yield return new WaitForSeconds(shotAliveSeconds);
|
yield return new WaitForSeconds(shotAliveSeconds);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user