It’s a frickin’ laser beam!
Handling the Input
What I thought I needed to deal with:
What I actually needed to deal with:
The short of it is that everything is an axis in the Input Manager which apparently means that everything returns data from Get Axis Raw.
The Attack Sequence
The goal of the Attack Sequence is to use composition and the single responsibility principal to compartmentalize functionality. Of course, having a laser beam as the basic attack means that I need an on/off switch for the attack. I imagine that most weapons, such as a blaster pistol, will simply ignore the off switch.
This is the first step in the sequence. The Attack Controller component could sit on any Game Object at this point. I have it placed on the ECM_Character object which is also has the Rigidbody and Easy Character Movement scripts on it. Note that the Animator is on the Model which is a first child of the ECM_Character object.
Is it wise for the Basic Attack method to hunt down the character object for a Basic Attack component? No. It’s sloppy but it works and I’ll revisit it later.
The Basic Attack component sits on the Weapon prefab of which Laser Rifle is a variant. Here’s the Inspector breakdown of the Laser Rifle prefab at this point in the development cycle:
The Basic Attack script’s only purpose in existence is to expose two Unity Events to the Inspector: Attack Started and Attack Ended. The purpose of this component is so that the Attack Controller doesn’t need to care WHAT starts a Basic Attack. It just needs to know that SOMETHING can handle it.
The Laser Beam component registers itself to the Attack Started and Attack Ended events. It is essentially an ON/OFF switch for the Particle System.
This method could look for a Particle System in the children, but there might be multiple systems in the hierarchy and we want to be sure to get the right one. This Particle System is mounted on the Muzzle game object which is positioned at the barrel of the gun.
Mounting the Weapon
The Equip component references the Weapon Right node that is set up in the video as well as referencing a prefab of the game object that will be instantiated in the right hand. Ignore the left hand reference for now.
The Equip script is very simple and simply validates the serialized fields and then instantiates the weapon as a child of the hand transform.