Many steps need to be performed as we have a lot of code to review together:
- To start, we are going to implement the BikeWeapon class. Because it's quite long, we will split it up into three segments:
using UnityEngine;
using System.Collections;
namespace Chapter.Decorator
{
public class BikeWeapon : MonoBehaviour
{
public WeaponConfig weaponConfig;
public WeaponAttachment mainAttachment;
public WeaponAttachment secondaryAttachment;
private bool _isFiring;
private IWeapon _weapon;
private bool _isDecorated;
void Start()
{
_weapon = new Weapon(weaponConfig);
}
The first segment is the initialization code. Note that we are setting the weapon's configuration at the Start().
For the second segment of the class, it is just GUI labels that will help us with debugging:
void OnGUI()
{
GUI.color = Color.green;
GUI.Label (
new Rect (5, 50, 150, 100),
"...