Advertisement
KingObsidian

Untitled

May 25th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CamAnimation : MonoBehaviour {
  5. public CharacterController playerController;
  6. public Animation anim; //Empty GameObject's animation component
  7. private bool isMoving;
  8.  
  9. private bool left;
  10. private bool right;
  11.  
  12. void CameraAnimations(){
  13. if(playerController.isGrounded == true){
  14. if(isMoving == true){
  15. if(left == true){
  16. if(!anim.isPlaying){//Waits until no animation is playing to play the next
  17. anim.Play("walkLeft");
  18. left = false;
  19. right = true;
  20. }
  21. }
  22. if(right == true){
  23. if(!anim.isPlaying){
  24. anim.Play("walkRight");
  25. right = false;
  26. left = true;
  27. }
  28. }
  29. }
  30. }
  31. }
  32.  
  33.  
  34. void Start () { //First step in a new scene/life/etc. will be "walkLeft"
  35. playerController = GameObject.Find("Player");
  36. left = true;
  37. right = false;
  38. }
  39.  
  40.  
  41. void Update () {
  42. float inputX = Input.GetAxis("Horizontal"); //Keyboard input to determine if player is moving
  43. float inputY = Input.GetAxis("Vertical");
  44.  
  45. if(inputX != 0 || inputY != 0){
  46. isMoving = true;
  47. }
  48. else if(inputX == 0 && inputY == 0){
  49. isMoving = false;
  50. }
  51.  
  52. CameraAnimations();
  53.  
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement