If you wish to test the code we just reviewed in your own instance of Unity, you need to follow these steps:
- Copy all the classes we just reviewed in your Unity project.
- Create an empty Unity scene.
- Add a new GameObject to the scene.
- Attach the following client script to the new GameObject:
using UnityEngine;
namespace Chapter.Decorator
{
public class ClientDecorator : MonoBehaviour
{
private BikeWeapon _bikeWeapon;
private bool _isWeaponDecorated;
void Start() {
_bikeWeapon =
(BikeWeapon)
FindObjectOfType(typeof(BikeWeapon));
}
void OnGUI()
{
if (!_isWeaponDecorated)
if (GUILayout.Button("Decorate Weapon")) {
_bikeWeapon.Decorate();
_isWeaponDecorated = !_isWeaponDecorated;
}
if (_isWeaponDecorated)
if (GUILayout.Button("Reset Weapon"))...