From e81f7808d7aa8617b918bdeb28bf535e37efddab Mon Sep 17 00:00:00 2001 From: Saibotk Date: Mon, 23 Apr 2018 18:38:43 +0200 Subject: [PATCH] GATLING GUN --- Assets/Scripts/Bullet.cs | 4 ++++ Assets/Scripts/Entities/Attack/GatlingGun.cs | 13 +++++++++++++ .../Scripts/Entities/Attack/GatlingGun.cs.meta | 11 +++++++++++ Assets/Scripts/Entities/Attack/MeleeAttack.cs | 2 +- Assets/Scripts/Entities/Attack/SingleShot.cs | 8 +++++--- Assets/Scripts/Entities/Player.cs | 18 ++++++++++++++++++ 6 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 Assets/Scripts/Entities/Attack/GatlingGun.cs create mode 100644 Assets/Scripts/Entities/Attack/GatlingGun.cs.meta diff --git a/Assets/Scripts/Bullet.cs b/Assets/Scripts/Bullet.cs index 5a35d93..faaf453 100644 --- a/Assets/Scripts/Bullet.cs +++ b/Assets/Scripts/Bullet.cs @@ -16,6 +16,10 @@ public class Bullet : MonoBehaviour { } + public void SetSpeed(float spd) { + speed = spd; + } + public void SetDamage(int dmg) { damage = dmg; } diff --git a/Assets/Scripts/Entities/Attack/GatlingGun.cs b/Assets/Scripts/Entities/Attack/GatlingGun.cs new file mode 100644 index 0000000..d018362 --- /dev/null +++ b/Assets/Scripts/Entities/Attack/GatlingGun.cs @@ -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; + } + + } +} diff --git a/Assets/Scripts/Entities/Attack/GatlingGun.cs.meta b/Assets/Scripts/Entities/Attack/GatlingGun.cs.meta new file mode 100644 index 0000000..b795fec --- /dev/null +++ b/Assets/Scripts/Entities/Attack/GatlingGun.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 947693703e16a8e4d9542d72d014e351 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Entities/Attack/MeleeAttack.cs b/Assets/Scripts/Entities/Attack/MeleeAttack.cs index 2b137d2..bb89f8a 100644 --- a/Assets/Scripts/Entities/Attack/MeleeAttack.cs +++ b/Assets/Scripts/Entities/Attack/MeleeAttack.cs @@ -8,7 +8,7 @@ namespace Assets.Scripts.Entities.Attack { int damage = 10; float cooldown = 1; - float range = 2f; + float range = 1f; GameObject owner; public MeleeAttack(GameObject owner) { diff --git a/Assets/Scripts/Entities/Attack/SingleShot.cs b/Assets/Scripts/Entities/Attack/SingleShot.cs index 88e3a50..08943e9 100644 --- a/Assets/Scripts/Entities/Attack/SingleShot.cs +++ b/Assets/Scripts/Entities/Attack/SingleShot.cs @@ -5,9 +5,10 @@ using UnityEngine; namespace Assets.Scripts.Entities.Attack { class SingleShot : IAttack { - int damage = 12; - float cooldown = 1; - int range = 4; + protected int damage = 12; + protected float cooldown = 1; + protected int range = 4; + protected float speed = 10; GameObject owner; GameObject bulletPrefab; Transform spawn; @@ -32,6 +33,7 @@ namespace Assets.Scripts.Entities.Attack { b.transform.position = spawn.position; Bullet bu = b.GetComponent(); bu.SetDamage(damage); + bu.SetSpeed(speed); bu.SetOwner(owner); GameController.instance.GetAudioControl().SfxPlay(0); } diff --git a/Assets/Scripts/Entities/Player.cs b/Assets/Scripts/Entities/Player.cs index 64309da..8d0816b 100644 --- a/Assets/Scripts/Entities/Player.cs +++ b/Assets/Scripts/Entities/Player.cs @@ -10,6 +10,9 @@ public class Player : Mob { [SerializeField] private int carDamage = 5; + private SingleShot singleShot; + private GatlingGun ggun; + private float nextAttackTime; public Player() : base(100) { } @@ -18,10 +21,25 @@ public class Player : Mob { SingleShot s = new SingleShot(this.gameObject); s.SetPrefab(bulletPrefab); s.SetSpawn(bulletSpawn); + singleShot = s; + GatlingGun g = new GatlingGun(this.gameObject); + g.SetPrefab(bulletPrefab); + g.SetSpawn(bulletSpawn); + ggun = g; SetAttack(s); } 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 ( Input.GetAxis("Fire") > 0 ) { Debug.Log("Attack pressed!");