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 weapon
  • The 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; ...

Get Procedural Content Generation for Unity Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.