Time for action – scripting the target
We only need one more piece before we can finish putting the target together.
That piece is a script. Create a new script in our
Scripts
folder and name itTarget
.First, in order to interact with our state machine, we need a reference to the
Animator
component. It is the component that you removed from the tank and the city. TheAnimator
component is what ties all of the pieces of animation together.public Animator animator;
It is followed by two float values that will dictate the range of time, in seconds, that our targets will sit in their idle states.
public float maxIdleTime = 10f; public float minIdleTime = 3f;
Next, we have three values that will hold the ID numbers of the parameters that we need to change. It is technically possible to just use the names of the parameters to set them, but using the ID number is much faster.
private int timeId = -1; private int wasHitId = -1; private int inTheFrontId = -1;
The last two variables will hold the ID numbers...