#pragma strict
@script RequireComponent( CharacterController )
@script AddComponentMenu("Camera-Control/Smooth Look At")
private var character : CharacterController;
private var thisTransform : Transform;
private var smooth : boolean = true;
var rotateTouchPad : Joystick;
var cameraPivot : Transform;
var camRotation : Vector2 = Vector2.zero;
var rotationSpeed : Vector2 = Vector2(50,25);
var xRotation : float;
var yRotation : float;
function Start ()
{
character = GetComponent( CharacterController );
thisTransform = GetComponent( Transform );
// Move the character to the correct start position in the level, if one exists
//var spawn = GameObject.Find( "PlayerSpawn" );
//if ( spawn )
//thisTransform.position = spawn.transform.position;
}
function EndGame()
{
//if ( rotateTouchPad )
//rotateTouchPad.Disable();
// Don't allow any more control changes when the game ends
//this.enabled = false;
}
function LookFunction ()
{
camRotation = rotateTouchPad.position;
camRotation.x *= rotationSpeed.x;
camRotation.y *= rotationSpeed.y;
camRotation *= Time.deltaTime;
//Rotate only the camera with x-axis input
cameraPivot.Rotate(0,camRotation.x,0,Space.World);
// Rotate only the camera with y-axis input
cameraPivot.Rotate(-camRotation.y,0,0);
if(cameraPivot.localRotation.x >= 340 && cameraPivot.localRotation.x <= 90)
{
var clampX = Mathf.Clamp(cameraPivot.localRotation.x,90,340);
cameraPivot.rotation = Quaternion.Euler(clampX,0,0);
}
if(smooth)
{
}
}
↧