Game Development Reference
In-Depth Information
Engage thrusters
Now, we will create the script to control our character:
1. We will create the CameraControl script that will control our entire menu; go to
Assets | Create | Javascript (for Unity JavaScript users) or Assets | Create | C#
(for C# users), name it CameraControl , double-click on it to launch
MonoDevelop , and then we will get our hands dirty with the code.
2. Open the CameraControl script file and type in the following code:
// Unity JavaScript user:
#pragma strict
@script RequireComponent (CharacterControl)
var smoothTime : float = 0.1f;
var maxSpeed : float = 150.0f;
var heightSmoothTime : float = 0.1f;
var distance : float = 2.5f;
var height : float = 0.75f;
private var _heightVelocity : float = 0.0f;
private var _angleVelocity : float = 0.0f;
private var _velocity : Vector3;
private var _targetTransform : Transform;
private var _cameraTransform : Transform;
private var _maxRotation : float;
private var _characterControl : CharacterControl;
private var _targetHeight : float = Mathf.Infinity;
private var _centerOffset : Vector3 = Vector3.zero;
// C# user:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(CharacterControl))]
public class CameraControl : MonoBehaviour {
public float smoothTime = 0.1f;
public float maxSpeed = 150.0f;
public float heightSmoothTime = 0.1f;
public float distance = 2.5f;
Search WWH ::




Custom Search