Search Unity

GunScript error

Discussion in 'Scripting' started by lenis0012, Sep 16, 2012.

  1. lenis0012

    lenis0012

    Joined:
    Sep 16, 2012
    Posts:
    3
    this is my GunScript

    when i have it disabled, my game works fine, when i enable it, the gun is stuck at my body (as it suppost to)
    but i cant move at all and look around!
    this works if i disable the GunScript
    when i move the camera it forces it back to the default location
    and my scene view screen is moving wheird when im not even doing anything
    i dont think this suppost to happend...

    it messes my entire game up!
    here is the code:
    Code (csharp):
    1.  
    2. var cameraObject : GameObject;
    3. @HideInInspector
    4. var targetXRotation : float;
    5. @HideInInspector
    6. var targetYRotation : float;
    7. @HideInInspector
    8. var targetXRotationV : float;
    9. @HideInInspector
    10. var targetYRotationV : float;
    11.  
    12. var rotateSpeed : float = 0.3;
    13. var holdHeight : float = -0.5;
    14. var holdSide : float = 0.5;
    15. var racioHipHold : float = 1;
    16. var hipToAimSpeed : float = 0.1;
    17. @HideInInspector
    18. var racioHipHoldV : float;
    19.  
    20. function Update ()
    21. {
    22.     if(Input.GetButton("Fire2"))
    23.     {
    24.         racioHipHold = Mathf.SmoothDamp(racioHipHold, 0, racioHipHoldV, hipToAimSpeed);
    25.     }
    26.     if(Input.GetButton("Fire2") == false)
    27.     {
    28.         racioHipHold = Mathf.SmoothDamp(racioHipHold, 1, racioHipHoldV, hipToAimSpeed);
    29.     }
    30.    
    31.     transform.position = cameraObject.transform.position + (Quaternion.Euler(0, targetYRotation, 0) * Vector3(holdSide * racioHipHold, holdHeight * racioHipHold, 0));
    32.    
    33.     targetXRotation = Mathf.SmoothDamp(targetXRotation, cameraObject.GetComponent(MouseLookScript).xRotation, targetXRotationV, rotateSpeed);
    34.     targetYRotation = Mathf.SmoothDamp(targetYRotation, cameraObject.GetComponent(MouseLookScript).yRotation, targetYRotationV, rotateSpeed);
    35.    
    36.     transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation, 0);
    37. }
    38.  
    it is using the LookScript:
    Code (csharp):
    1.  
    2. var defaultCameraAngle : float = 60;
    3. @HideInInspector
    4. var currentTargetCameraAngle : float = 60;
    5. @HideInInspector
    6. var racioZoom : float = 1;
    7. @HideInInspector
    8. var racioZoomV : float;
    9.  
    10. var racioZoomSpeed : float = 0.2;
    11.  
    12. var lookSensitivity : float = 5;
    13. @HideInInspector
    14. var yRotation : float;
    15. @HideInInspector
    16. var xRotation : float;
    17. @HideInInspector
    18. var currentYRotation : float;
    19. @HideInInspector
    20. var currentXRotation : float;
    21. @HideInInspector
    22. var yRotationV : float;
    23. @HideInInspector
    24. var xRotationV : float;
    25. var lookSmoothDamp : float = 0.1;
    26.  
    27. function Update ()
    28. {
    29.     yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
    30.     xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity;
    31.    
    32.     xRotation = Mathf.Clamp(xRotation, -90, 90);
    33.    
    34.     currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp);
    35.     currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp);
    36.  
    37.     transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
    38. }
    39.  
     
    Last edited: Sep 16, 2012
  2. BlackMantis

    BlackMantis

    Joined:
    Feb 7, 2010
    Posts:
    1,475
    Let he forum know what errors you are getting, and what lines they are on. Also I helps to describe what is going on in the game as well. After all it only takes one type o to create havoc lol.
     
  3. lenis0012

    lenis0012

    Joined:
    Sep 16, 2012
    Posts:
    3
    changed it ;)