From 5fd5f27ac6b8308e91d20ac8ffa6a258897d779d Mon Sep 17 00:00:00 2001 From: Noah4ever <66632359+Noah4ever@users.noreply.github.com> Date: Wed, 19 Jan 2022 21:41:02 +0100 Subject: [PATCH] Abstract Gun.cs & Weapon.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gun.cs muss vlt noch umbenannt werden, weil Gun Pistole heißt und nicht ein oberbegriff für alle Waffen ist. --- Assets/Scripts/Weapons/Gun.cs | 46 +++++++++++++++++ Assets/Scripts/Weapons/Gun.cs.meta | 11 ++++ Assets/Scripts/Weapons/Melee.cs | 18 +++++++ Assets/Scripts/Weapons/Melee.cs.meta | 11 ++++ Assets/Scripts/Weapons/Weapon.cs | 71 ++++++-------------------- Assets/Scripts/Weapons/Weapon.cs.meta | 2 +- Assets/Scripts/Weapons/Weapon1.cs | 62 ++++++++++++++++++++++ Assets/Scripts/Weapons/Weapon1.cs.meta | 11 ++++ 8 files changed, 177 insertions(+), 55 deletions(-) create mode 100644 Assets/Scripts/Weapons/Gun.cs create mode 100644 Assets/Scripts/Weapons/Gun.cs.meta create mode 100644 Assets/Scripts/Weapons/Melee.cs create mode 100644 Assets/Scripts/Weapons/Melee.cs.meta create mode 100644 Assets/Scripts/Weapons/Weapon1.cs create mode 100644 Assets/Scripts/Weapons/Weapon1.cs.meta diff --git a/Assets/Scripts/Weapons/Gun.cs b/Assets/Scripts/Weapons/Gun.cs new file mode 100644 index 0000000..56b97ff --- /dev/null +++ b/Assets/Scripts/Weapons/Gun.cs @@ -0,0 +1,46 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public abstract class Gun +{ + // All types of guns + public enum types + { + Rifle, Pistole, Melee, Grenade + } + // Type of gun + private types type; + // Name of gun + private string name; + // Damage of gun + private float damage; + // Strength of throw + private float dropForce; + + //private Animator gunAnimator; + //private Transform gunRightREF; + //private Transform gunLeftREF; + + // Constructor + public Gun() + { + this.type = types.Rifle; + this.name = "Weapon"; + this.damage = 0f; + this.dropForce = 10f; + } + public Gun(types type, string name, float damage, float dropforce) + { + this.type = type; + this.name = name; + this.damage = damage; + this.dropForce = dropforce; + } + + // Getter + private types Type { get => type; } + private string Name { get => name; } + private float Damage { get => damage; } + public float DropForce { get => dropForce; } +} diff --git a/Assets/Scripts/Weapons/Gun.cs.meta b/Assets/Scripts/Weapons/Gun.cs.meta new file mode 100644 index 0000000..93bc634 --- /dev/null +++ b/Assets/Scripts/Weapons/Gun.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c7ebf5d2db3fbca44bf8350f3aab7df3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Weapons/Melee.cs b/Assets/Scripts/Weapons/Melee.cs new file mode 100644 index 0000000..bc38596 --- /dev/null +++ b/Assets/Scripts/Weapons/Melee.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Melee : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Weapons/Melee.cs.meta b/Assets/Scripts/Weapons/Melee.cs.meta new file mode 100644 index 0000000..91ec59e --- /dev/null +++ b/Assets/Scripts/Weapons/Melee.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9cbb6ae29437e104fa12f4d4f22ab3f8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Weapons/Weapon.cs b/Assets/Scripts/Weapons/Weapon.cs index 5c602f4..08af0c9 100644 --- a/Assets/Scripts/Weapons/Weapon.cs +++ b/Assets/Scripts/Weapons/Weapon.cs @@ -2,61 +2,24 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class Weapon : MonoBehaviour +public class Weapon : Gun { - public enum weaponKinds - { - Rifle, Pistole, Knife, Grenade - } - [Header("Weapon Info")] - [SerializeField] weaponKinds weaponKind; - [SerializeField] float dropForce = 10f; - [SerializeField] float hitForce = 100f; - [SerializeField] int damage = 0; - [SerializeField] float firerate = 0; - [SerializeField] float recoilStrength = 0; - [SerializeField] int currentAmmunition = 0; - [SerializeField] int magazinSize = 0; - [SerializeField] int totalAmmunition = 0; - [SerializeField] GameObject bulletExit; - [SerializeField] bool toCloseToWall = false; - [SerializeField] bool allowAction = true; - [Header("")] - [SerializeField] Animator weaponAnimator; - [SerializeField] Transform gunRightREF; - [SerializeField] Transform gunLeftREF; + // Firerate of weapon + private float firerate; + // Strength of recoil + private float recoilStrength; + // Current ammunition in magazin + private int currentAmmunition; + // Full magazin Size + private int magazinSize; + // Total ammunition + private int totalAmmunition; + // Bullet exit (Muzzle) + private GameObject bulletExit; + // Allow action of weapon (shoot, reload, aim, drop, ...) + private bool allowAction; - //[Header("Grenade")] - private bool hasBeenThrown = false; - - public weaponKinds WeaponKind { get => weaponKind; } - public float DropForce { get => dropForce; set => dropForce = value; } - public int Damage { get => damage; set => damage = value; } - public float Firerate { get => firerate; set => firerate = value; } - public float RecoilStrength { get => recoilStrength; set => recoilStrength = value; } - public int CurrentAmmunition { get => currentAmmunition; set => currentAmmunition = value; } - public int MagazinSize { get => magazinSize; set => magazinSize = value; } - public int TotalAmmunition { get => totalAmmunition; set => totalAmmunition = value; } - public GameObject BulletExit { get => bulletExit; } - public bool ToCloseToWall { get => toCloseToWall; set => toCloseToWall = value; } - public bool AllowAction { get => allowAction; set => allowAction = value; } - public Animator WeaponAnimator { get => weaponAnimator; } - public Transform GunLeftREF { get => gunLeftREF; } - public Transform GunRightREF { get => gunRightREF; } - public bool HasBeenThrown { get => hasBeenThrown; set => hasBeenThrown = value; } - public float HitForce { get => hitForce; set => hitForce = value; } - - private void Start() { - CurrentAmmunition = MagazinSize; - } - - // When to close to a wall, the player puts the weapon upright (Change size on weapon collider where isTrigger == true) - /*private void OnCollisionEnter(Collision collision) { - toCloseToWall = true; - Debug.Log(collision.transform.name); - } - private void OnCollisionExit(Collision collision) { - toCloseToWall = false; - }*/ + // Getter + } diff --git a/Assets/Scripts/Weapons/Weapon.cs.meta b/Assets/Scripts/Weapons/Weapon.cs.meta index 507378c..b63cf65 100644 --- a/Assets/Scripts/Weapons/Weapon.cs.meta +++ b/Assets/Scripts/Weapons/Weapon.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c98f5c47a8b7dd64f86fd6f42c4d6e5e +guid: f62d078a0e7aedc429438f136b425545 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/Weapons/Weapon1.cs b/Assets/Scripts/Weapons/Weapon1.cs new file mode 100644 index 0000000..8f1832f --- /dev/null +++ b/Assets/Scripts/Weapons/Weapon1.cs @@ -0,0 +1,62 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Weapon1 : MonoBehaviour +{ + public enum weaponKinds + { + Rifle, Pistole, Knife, Grenade + } + [Header("Weapon Info")] + [SerializeField] weaponKinds weaponKind; + [SerializeField] float dropForce = 10f; + [SerializeField] float hitForce = 100f; + [SerializeField] int damage = 0; + [SerializeField] float firerate = 0; + [SerializeField] float recoilStrength = 0; + [SerializeField] int currentAmmunition = 0; + [SerializeField] int magazinSize = 0; + [SerializeField] int totalAmmunition = 0; + [SerializeField] GameObject bulletExit; + [SerializeField] bool toCloseToWall = false; + [SerializeField] bool allowAction = true; + [Header("")] + [SerializeField] Animator weaponAnimator; + [SerializeField] Transform gunRightREF; + [SerializeField] Transform gunLeftREF; + + //[Header("Grenade")] + private bool hasBeenThrown = false; + + public weaponKinds WeaponKind { get => weaponKind; } + public float DropForce { get => dropForce; set => dropForce = value; } + public int Damage { get => damage; set => damage = value; } + public float Firerate { get => firerate; set => firerate = value; } + public float RecoilStrength { get => recoilStrength; set => recoilStrength = value; } + public int CurrentAmmunition { get => currentAmmunition; set => currentAmmunition = value; } + public int MagazinSize { get => magazinSize; set => magazinSize = value; } + public int TotalAmmunition { get => totalAmmunition; set => totalAmmunition = value; } + public GameObject BulletExit { get => bulletExit; } + public bool ToCloseToWall { get => toCloseToWall; set => toCloseToWall = value; } + public bool AllowAction { get => allowAction; set => allowAction = value; } + public Animator WeaponAnimator { get => weaponAnimator; } + public Transform GunLeftREF { get => gunLeftREF; } + public Transform GunRightREF { get => gunRightREF; } + public bool HasBeenThrown { get => hasBeenThrown; set => hasBeenThrown = value; } + public float HitForce { get => hitForce; set => hitForce = value; } + + private void Start() { + CurrentAmmunition = MagazinSize; + } + + // When to close to a wall, the player puts the weapon upright (Change size on weapon collider where isTrigger == true) + /*private void OnCollisionEnter(Collision collision) { + toCloseToWall = true; + Debug.Log(collision.transform.name); + } + private void OnCollisionExit(Collision collision) { + toCloseToWall = false; + }*/ + +} diff --git a/Assets/Scripts/Weapons/Weapon1.cs.meta b/Assets/Scripts/Weapons/Weapon1.cs.meta new file mode 100644 index 0000000..507378c --- /dev/null +++ b/Assets/Scripts/Weapons/Weapon1.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c98f5c47a8b7dd64f86fd6f42c4d6e5e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: