Graphics Reference
In-Depth Information
_animation.CrossFade(walkAnimation.name);
}
else if(_characterState == CharacterState.Walking) {
_animation[walkAnimation.name].speed =
Mathf.Clamp(controller.velocity.magnitude,
0.0f, walkMaxAnimationSpeed);
_animation.CrossFade(walkAnimation.name);
}
}
}
}
public float GetSpeed ()
{
return moveSpeed;
}
public Vector3 GetDirection ()
{
return moveDirection;
}
public bool IsMoving ()
{
return Mathf.Abs(vert) + Mathf.Abs(horz) > 0.5f;
}
public void Reset ()
{
gameObject.tag = "Player";
}
}
5.2.1 Script Breakdown
The script derives from ExtendedCustomMonoBehavior, as described in Chapter 4, and it
adds some extra common variables to the class:
public class BaseTopDown : ExtendedCustomMonoBehavior
{
By using @script RequireComponent, this code tells the Unity engine that it requires
the controller specified by RequireComponent. If there is not one already attached to the
gameObject this script is attached to, the Unity engine will automatically add an instance
of one at runtime, although it is intended that the CharacterController reference be set up
in the Unity editor before the script is run:
// Require a character controller to be attached to the same game object
// @script RequireComponent(CharacterController)
Note that many of the variable declarations will make more sense later in this section, once
we get to look at the actual code using them. For that reason, we skip most of them here and
just highlight the ones that either stand out or require more information.
Search WWH ::




Custom Search