Game Development Reference
In-Depth Information
Figure 11-27. The laser beam intersecting the hat base
5.
In the RayGun's Mouse Look component, Decrease the Minimum Y until the
beam no longer intersects the cap base, somewhere around -35 .
6.
Stop Play mode, and make the change permanent.
Now would be a good time to address another little detail. Currently, the top of the cap is
deactivated. The problem is, of course, that the beam comes through even if it were closed.
Obviously, you will want to turn it off and on to coincide with the Gnome armed state. It should only
be on during the Gnome armed state.
There are a lot of ways you could implement this functionality, but for this task you will be accessing
the Animator component's state information.
1.
Open the LaserController script.
The script resides on the GardenGnome object where the Animator component is located. It will
require access to the Laser Point.
2.
Add the following variable:
public GameObject laserPoint;
In the Update function, below the two if (Input lines, add the following:
3.
//check for hat state
if(animator.GetCurrentAnimatorStateInfo(1).IsName("Laser.Gnome armed") ) BeamOn();
else BeamOff();
Using the GetCurrentAnimatorStateInfo for layer 1 (layer 0 is the base layer), you check to see if the
active state is named “ Laser.Gnome armed .” If it is, you call the little function that activates the Laser
Point with its Line Renderer component. If not, you call the function that deactivates it.
 
Search WWH ::




Custom Search