O'Reilly logo

Procedural Content Generation for Unity Game Development by Ryan Watkins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required