Graphics Reference
In-Depth Information
myTransform.localPosition = new Vector3
(myTransform.localPosition.x,
myTransform.localPosition.y, thePos);
}
}
}
5.2 Humanoid Character
The human control script uses Unity's character controller and is based on the third-
person character controller provided by Unity (which is provided free, as part of the
included assets with the Unity game engine).
The complete BaseTopDown.cs script looks like this:
using UnityEngine;
using System.Collections;
public class BaseTopDown : ExtendedCustomMonoBehavior
{
public AnimationClip idleAnimation;
public AnimationClip walkAnimation;
public float walkMaxAnimationSpeed = 0.75f;
public float runMaxAnimationSpeed = 1.0f;
// When did the user start walking (Used for going into run after a
// while)
private float walkTimeStart= 0.0f;
// we've made the following variable public so that we can use an
// animation on a different gameObject if needed
public Animation _animation;
enum CharacterState {
Idle = 0,
Walking = 1,
Running = 2,
}
private CharacterState _characterState;
// The speed when walking
public float walkSpeed= 2.0f;
// after runAfterSeconds of walking we run with runSpeed
public float runSpeed= 4.0f;
public float speedSmoothing= 10.0f;
public float rotateSpeed= 500.0f;
public float runAfterSeconds= 3.0f;
// The current move direction in x-z
private Vector3 moveDirection= Vector3.zero;
// The current vertical speed
private float verticalSpeed= 0.0f;
Search WWH ::




Custom Search