1
0
Fork 0

GATLING GUN

This commit is contained in:
Saibotk 2018-04-23 18:38:43 +02:00
parent f2a3904b21
commit e81f7808d7
6 changed files with 52 additions and 4 deletions

View file

@ -16,6 +16,10 @@ public class Bullet : MonoBehaviour {
} }
public void SetSpeed(float spd) {
speed = spd;
}
public void SetDamage(int dmg) { public void SetDamage(int dmg) {
damage = dmg; damage = dmg;
} }

View file

@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Assets.Scripts.Entities.Attack {
class GatlingGun : SingleShot {
public GatlingGun(GameObject owner) : base(owner) {
damage = 5;
cooldown = 0.1f;
speed = 20;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 947693703e16a8e4d9542d72d014e351
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -8,7 +8,7 @@ namespace Assets.Scripts.Entities.Attack {
int damage = 10; int damage = 10;
float cooldown = 1; float cooldown = 1;
float range = 2f; float range = 1f;
GameObject owner; GameObject owner;
public MeleeAttack(GameObject owner) { public MeleeAttack(GameObject owner) {

View file

@ -5,9 +5,10 @@ using UnityEngine;
namespace Assets.Scripts.Entities.Attack { namespace Assets.Scripts.Entities.Attack {
class SingleShot : IAttack { class SingleShot : IAttack {
int damage = 12; protected int damage = 12;
float cooldown = 1; protected float cooldown = 1;
int range = 4; protected int range = 4;
protected float speed = 10;
GameObject owner; GameObject owner;
GameObject bulletPrefab; GameObject bulletPrefab;
Transform spawn; Transform spawn;
@ -32,6 +33,7 @@ namespace Assets.Scripts.Entities.Attack {
b.transform.position = spawn.position; b.transform.position = spawn.position;
Bullet bu = b.GetComponent<Bullet>(); Bullet bu = b.GetComponent<Bullet>();
bu.SetDamage(damage); bu.SetDamage(damage);
bu.SetSpeed(speed);
bu.SetOwner(owner); bu.SetOwner(owner);
GameController.instance.GetAudioControl().SfxPlay(0); GameController.instance.GetAudioControl().SfxPlay(0);
} }

View file

@ -10,6 +10,9 @@ public class Player : Mob {
[SerializeField] [SerializeField]
private int carDamage = 5; private int carDamage = 5;
private SingleShot singleShot;
private GatlingGun ggun;
private float nextAttackTime; private float nextAttackTime;
public Player() : base(100) { } public Player() : base(100) { }
@ -18,10 +21,25 @@ public class Player : Mob {
SingleShot s = new SingleShot(this.gameObject); SingleShot s = new SingleShot(this.gameObject);
s.SetPrefab(bulletPrefab); s.SetPrefab(bulletPrefab);
s.SetSpawn(bulletSpawn); s.SetSpawn(bulletSpawn);
singleShot = s;
GatlingGun g = new GatlingGun(this.gameObject);
g.SetPrefab(bulletPrefab);
g.SetSpawn(bulletSpawn);
ggun = g;
SetAttack(s); SetAttack(s);
} }
void Update() { void Update() {
if(Input.GetKeyDown(KeyCode.G)) {
if(attack != ggun) {
attack = ggun;
Debug.Log("Switched to GatlingGun");
} else {
attack = singleShot;
Debug.Log("Switched to SingleShot");
}
}
if ( Time.timeSinceLevelLoad >= nextAttackTime && attack != null) { if ( Time.timeSinceLevelLoad >= nextAttackTime && attack != null) {
if ( Input.GetAxis("Fire") > 0 ) { if ( Input.GetAxis("Fire") > 0 ) {
Debug.Log("Attack pressed!"); Debug.Log("Attack pressed!");