Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

So i need help with my first game attempt.....

Discussion in 'Scripting' started by Ascend_Dark, Feb 21, 2015.

  1. Ascend_Dark

    Ascend_Dark

    Joined:
    Feb 21, 2015
    Posts:
    1
    This is the mouselook script for the gun but it wont work properly with the else can someone help me understand why?

    #pragma strict
    var LookSens : float = 5;
    var yRotation : float;
    var xRotation : float;
    var CurrentXRotation : float;
    var CurrentYRotation : float;
    var yRotationV : float;
    var XRotationV : float;
    var LookSmoothness : float = 0.1;
    var bobSpeed : float = 1;
    var stepCounter : float;
    var bobAmountX : float =1;
    var bobAmountY : float =1;
    var lastPositon : Vector3;
    var heightRatio : float;
    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()
    {
    lastPositon = transform.parent.position;
    }
    function Update ()
    {
    if(aimingTrue == 1);
    }
    cameraZoom = Mathf.SmoothDamp(cameraZoom, 1, cameraZoomV, cameraZoomSpeed);
    {

    else

    }

    cameraZoom = Mathf.SmoothDamp(cameraZoom, 0, cameraZoomV, cameraZoomSpeed);
    {
    camera.fieldOfView = Mathf.Lerp(targetCamera, cameraDefault, cameraZoom);
    if (Transform.parent.GetComponent(Movement).grounded)
    {
    stepCounter += Vector3.Distance(lastPositon, Transform.parent.position) * bobSpeed;
    }
    transform.localPosition.x = Mathf.Sin(stepCounter) * bobAmountX;
    transform.localPosition.y = (Mathf.Sin(stepCounter * 2) * bobAmountY * -1) + (transform.parent.localScale.y * heightRatio) - (transform.parent.localScale.y/2);

    lastPositon = transform.parent.position;

    yRotation += Input.GetAxis("Mouse X") * LookSens;
    xRotation -= Input.GetAxis("Mouse Y") * LookSens;

    xRotation = Mathf.Clamp(xRotation, -80, 100);

    CurrentXRotation = Mathf.SmoothDamp(CurrentXRotation, xRotation, XRotationV, LookSmoothness);
    CurrentYRotation = Mathf.SmoothDamp(CurrentYRotation, yRotation, yRotationV, LookSmoothness);

    transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
  3. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    The "else" is written inside the braces ('{' and '}'), where it should be before them. Then, the stuff you want to happen when the test does not pass should go between the braces.