Game Development Reference
In-Depth Information
Prepare for Lift Off
Before we start coding, we need to get rid of the built-in Third-person Controller
and Third-person Camera scripts. So, let's go to Heroine_animate in the Hierarchy
View , under the Inspector view, right-click the Third-person Camera script, and then click
Remove Component . We will see the pop-up window that says we'll lose the prefab if we
remove it. We can just click on the OK buton to remove it because we already created our
prefab. Then, we go to Third-person Controller , right-click and select Remove Component to
remove it. Now, we are ready to create our character control script.
Engage Thrusters
Now we will create the script to control our character:
1. Go to Assets | Create | JavaScript and name it CharacterControl , and then
right-click on this script and click Sync MonoDevelop Project (or double-click it
if you have already set MonoDevelop as your main editor, if not it will open the
default script editor either Unitron or UniScite ) to open MonoDevelop , and we
are ready to code.
2. We start by adding these parameters as follows:
// Require a character controller to be attached to the same game
object
@script RequireComponent(CharacterController)
//All Animation Clip Params
public var idleAnimation : AnimationClip;
public var walkAnimation : AnimationClip;
public var runAnimation : AnimationClip;
public var jumpPoseAnimation : AnimationClip;
public var fallPoseAnimation : AnimationClip;
//Animation Clip Speed
public var jumpAnimationSpeed : float = 4;
public var fallAnimationSpeed : float = 0.1;
public var runAnimationSpeed : float = 1.5;
public var walkAnimationSpeed : float = 1.5;
public var idleAnimationSpeed : float = 0.5;
public var speed : float = 2; //Walk speed
public var runSpeed : float = 5.0;
public var jumpSpeed : float = 8.0;
public var gravity : float = 20.0;
private var controller : CharacterController;
 
Search WWH ::




Custom Search