shooting example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class TripleRifle : Weapon { | |
private readonly BulletPool bulletPool; | |
private float cooldownTime; | |
public TripleRifle( BulletPool bulletPool ) { | |
this.bulletPool = bulletPool; | |
} | |
public void Cooldown( float time ) { | |
cooldownTime -= time; | |
} | |
public void Fire( Vector2 position, Vector2 direction ) { | |
if ( cooldownTime <= 0f ) { | |
LaunchBullet( position, direction, 10f ); | |
LaunchBullet( position, Quaternion.Euler( 0f, 0f, 30f ) * direction, 10f ); | |
LaunchBullet( position, Quaternion.Euler( 0f, 0f, -30f ) * direction, 10f ); | |
cooldownTime = 0.1f; | |
} | |
} | |
private void LaunchBullet( Vector2 position, Vector2 direction, float speed ) { | |
Bullet bullet = bulletPool.Spawn(); | |
bullet.SetPosition( position ); | |
bullet.SetVelocity( direction * speed ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment