Created
November 20, 2017 18:21
-
-
Save LeviVisser/caacf9838e30dc8944600b66d981e336 to your computer and use it in GitHub Desktop.
Weapon system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
/** | |
* A ship contains a weapon system | |
* This system monitors all the available weapons on the ship and can turn them on or off | |
* */ | |
public class WeaponSystem : MonoBehaviour { | |
//Public list of weapons in weapon system, needs to be public for accessibility for weapon system upgrades or specific weapon damage. | |
public List<Weapon> Weapons; | |
// Use this for initialization | |
void Start () { | |
Weapons.Find(w => w.weaponType.Equals(EWeaponType.laser)).Activate(); | |
Weapons.Find(w => !w.weaponType.Equals(EWeaponType.laser)).Deactivate(); | |
} | |
// Update is called once per frame | |
void Update () { | |
CheckSelectedWeapon(); | |
} | |
/// <summary> | |
/// Checks if a different weapon needs to be activated | |
/// </summary> | |
void CheckSelectedWeapon() | |
{ | |
if (Input.GetKey(KeyBinds.MainWeaponSelect)) | |
{ | |
Weapons.Find(w => w.weaponType.Equals(EWeaponType.laser)).Activate(); | |
Weapons.Find(w => !w.weaponType.Equals(EWeaponType.laser)).Deactivate(); | |
} | |
if (Input.GetKey(KeyBinds.MissileSelect)) | |
{ | |
Weapons.Find(w => w.weaponType.Equals(EWeaponType.missile)).Deactivate(); | |
Weapons.Find(w => !w.weaponType.Equals(EWeaponType.missile)).Activate(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment