Skip to content

Instantly share code, notes, and snippets.

@daleth90
Created Jul 26, 2017
Embed
What would you like to do?
shooting example
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