First Person Shooter Problem with the Scrip
I m making a FPS game in unity 3D but i have a problem with the scrip (First person view) is a only mistake but really give a big headache, i try to fix the mistake but the more I try gives me more mistakes, someone could headache a hand in the scrip and tell me that I did wrong ?, I know that the error is on the line 41 but when I try to fix, I added an error in the 45, to if I have error in the 41 and 45, please, I thank the help of whoever.
The Scrip is here:
pragma strict
public enum RotAxis {X = 0, Y = 1}
var RotAxisRotationXY = RotAxis.X || RotAxis.Y; var SensivityX : float = 25.0f; var SensivityY : float = 2.0f; var RotationX : float = 0.0f; var MinimumX : float = -360.0f; var MaximumX: float = 360.0f; var RotationY : float = 0.0f; var MinimumY : float = -45.0f; var MaximumY: float = 45.0f; var XQuat : Quaternion; var YQuat : Quaternion; var OrigRotation : Quaternion; var bobSpeed : float = 1; var stepCounter ; float; var bobAmountX; float = 1; var bobAmountY; float = 1; var lastPosition : Vector3; var heightRatio : float = 0.9; var aimingTrue : float = 1; var cameraDefault : float = 60; var targetCamera : float = 60; var cameraZoom : float = -1; var cameraZoomV : float; var cameraZoomSpeed : float = 0.1;
function Awake () { lastPosition = transform.parent.position; }
function Update () { if(aimingTrue == 1); { cameraZoom = Mathf.SmoothDamp(cameraZoom, 1, cameraZoomV, cameraZoomSpeed); } else { cameraZoom = Mathf.SmoothDamp(cameraZoom, 0, cameraZoomV, cameraZoomSpeed); } } { if(RotAxisRotationXY == RotAxisRotationXY.X) { camera.fieldOfView = Mathf.Lerp (targetCamera, cameraDefault, cameraZoom); if(transform.parent.GetComponent(Movement).grounded) { stepCountier += Vector3.Distance(lastPosition, transform.parent.position) bobSpeed; } transform.localPosition.x = Mathf.Sin(stepCounter) bobAmountX; transform.localPosition.y = (Mathf.Sin(stepCounter) bobAmountY -1) + (transform.parent.localScale.y * heightRatio) - (transform.parent.localScale.y/2);
lastPosition = transform.parent.position;
RotationX += Input.GetAxis("Mouse X") * SensivityX * Time.deltaTime;
RotationX = ClampAngle(RotationX, MinimumX, MaximumX);
OrigRotation = XQuat = Quaternion.AngleAxis(RotationX, Vector3.up);
transform.localRotation = OrigRotation * XQuat;
}
if(RotAxisRotationXY == RotAxisRotationXY.Y)
{
RotationY -= Input.GetAxis("Mouse Y") * SensivityY * Time.deltaTime;
RotationY = ClampAngle(RotationY, MinimumY, MaximumY);
OrigRotation = YQuat = Quaternion.AngleAxis(RotationY, Vector3.right);
transform.localRotation = OrigRotation * YQuat;
}
}
static function ClampAngle(Angle : float, Min : float, Max : float) : float { if(Angle < -360.0f) Angle += 360.0f; if(Angle > 360.0f) Angle -= 360.0f; return Mathf.Clamp(Angle, Min, Max); }
For who not can find the line 41 and the 45, it's in "else" and "}"
Please place all of the code in the correct format. Without proper formatting, it is impossible to answer the question.
Your answer