Modular weapon scripts
Our modular weapon script will do the following three main actions:
The
Weapon
script will create the connection to the player and the weaponThe player will need to carry and use the weapon
The script will drive the scripted animation, and it will also drive the the random construction of the weapon from the weapon component
We are going to place some hooks in the class definition as empty functions that we will fill in when we have some more information. Let's take a look at the full Weapon
class script that's shown in Code Snip 6.1:
1 using UnityEngine; 2 using System.Collections; 3 4 public class Weapon : MonoBehaviour { 5 6 public bool inPlayerInventory = false; 7 8 private Player player; 9 private WeaponComponents[] weaponsComps; 10 private bool weaponUsed = false; 11 12 public void AcquireWeapon () {} 13 14 void Update () {} 15 16 public void useWeapon () {} 17 18 public void enableSpriteRender (bool isEnabled) {} 19 20 public Sprite getComponentImage...