Game Development Reference
In-Depth Information
public float height = 0.75f;
float _heightVelocity = 0.0f;
float _angleVelocity = 0.0f;
Vector3 _velocity;
Transform _targetTransform;
Transform _cameraTransform;
float _maxRotation;
CharacterControl _characterControl;
float _targetHeight = Mathf.Infinity;
Vector3 _centerOffset = Vector3.zero;
}
Using the preceding code, we created all the variables required for this script.
3. Next, we will start creating the first function, Awake() , using the following code
to get the camera transform and the CharacterController component:
// Unity JavaScript user:
function Awake () {
_cameraTransform = Camera.main.transform;
_targetTransform = transform;
_characterControl =
GetComponent.<CharacterControl>();
}
// C# user:
void Awake () {
_cameraTransform = Camera.main.transform;
_targetTransform = transform;
_characterControl =
GetComponent<CharacterControl>();
}
4. Then, we create the Start() function as follows, to get the center position of
the target, which is the character we are pointing at:
Search WWH ::




Custom Search