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 Rifle : Weapon {
private readonly BulletPool bulletPool;
private float cooldownTime;
public Rifle( BulletPool bulletPool ) {
this.bulletPool = bulletPool;
}
public void Cooldown( float time ) {
cooldownTime -= time;
}
public void Fire( Vector2 position, Vector2 direction ) {
if ( cooldownTime <= 0f ) {
Bullet bullet = bulletPool.Spawn();
bullet.SetPosition( position );
bullet.SetVelocity( direction * 10f );
cooldownTime = 0.1f;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment