Search Unity

Animation Error

Discussion in 'Editor & General Support' started by Nightmare Games, Jun 18, 2013.

  1. Nightmare Games

    Nightmare Games

    Joined:
    Sep 5, 2012
    Posts:
    201
    SORRY FOR THE MUSIC I WAS ON PANDORA



    Here is the script im using:
    Code (csharp):
    1. var lookSensitivity : float = 5;
    2.  
    3. @HideInInspector
    4.  
    5. var currentXRotation : float;
    6.  
    7. @HideInInspector
    8.  
    9. var currentYRotation : float;
    10.  
    11. @HideInInspector
    12.  
    13. var xRotation : float;
    14.  
    15. @HideInInspector
    16.  
    17. var yRotation : float;
    18.  
    19. @HideInInspector
    20.  
    21. var xRotationVelocity : float;
    22.  
    23. @HideInInspector
    24.  
    25. var yRotationVelocity : float;
    26.  
    27. var lookSmoothDamp : float = 5;
    28.  
    29. var paused : boolean = false;
    30.  
    31. //for Pause Menu
    32.  
    33. var guiBackround : GameObject;
    34.  
    35. var pauseMenu : GameObject;
    36.  
    37. // for peeking
    38.  
    39. var Cam : GameObject;
    40.  
    41. static var nextToWall = false;
    42.  
    43. // Flashlight (Not the actual flashlight model just the spotlight
    44.  
    45. var Flashlight : GameObject;
    46.  
    47.  
    48.  
    49. function Start()
    50.  
    51. {
    52.  
    53.         nextToWall = false;
    54.  
    55.         Flashlight.active=false;
    56.  
    57. }
    58.  
    59.  
    60.  
    61. function Update()
    62.  
    63. {
    64.  
    65.         if(Input.GetKeyDown("escape")  paused == false)
    66.  
    67.    {  
    68.  
    69.    paused = true;    
    70.  
    71.    Time.timeScale = 0;
    72.  
    73.    guiBackround.active=true;
    74.  
    75.    pauseMenu.active=true;  
    76.  
    77.    }
    78.  
    79.    else if(Input.GetKeyDown("escape")  paused == true)
    80.  
    81.    {      
    82.  
    83.    paused = false;  
    84.  
    85.    Time.timeScale = 1;
    86.  
    87.    guiBackround.active=false;
    88.  
    89.    pauseMenu.active=false;
    90.  
    91.    }
    92.  
    93.    else if(nextToWall == false  Input.GetKeyDown(KeyCode.Q))
    94.  
    95.    {
    96.  
    97.         animation.Play("Peek(Q)");
    98.  
    99.    }
    100.  
    101.     else if(nextToWall == false  Input.GetKeyDown(KeyCode.E))
    102.  
    103.         {
    104.  
    105.                 animation.Play();
    106.  
    107.         }
    108.  
    109.     else if(nextToWall == true)
    110.  
    111.         {
    112.  
    113.                 // Stop all animations
    114.  
    115.         animation.Stop();
    116.  
    117.         }
    118.  
    119.         else if(Input.GetKeyDown(KeyCode.F)  Flashlight.active==false)
    120.  
    121.    {      
    122.  
    123.                 Flashlight.active=true;
    124.  
    125.    }
    126.  
    127.         else if(Input.GetKeyDown(KeyCode.F)  Flashlight.active==true)
    128.  
    129.    {      
    130.  
    131.                 Flashlight.active=false;
    132.  
    133.    }
    134.  
    135.         yRotation += Input.GetAxis("MouseX") * lookSensitivity;
    136.  
    137.         xRotation -= Input.GetAxis("MouseY") * lookSensitivity;
    138.  
    139.        
    140.  
    141.         xRotation = Mathf.Clamp(xRotation, -90, 90);
    142.  
    143.        
    144.  
    145.         currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationVelocity, lookSmoothDamp);
    146.  
    147.         currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationVelocity, lookSmoothDamp);
    148.  
    149.        
    150.  
    151.         transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
    152.  
    153. }