Advertisement
KingObsidian

Untitled

Sep 1st, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class FPS : MonoBehaviour
  5. {
  6. public float speed = 3.0F;
  7. public float rotateSpeed = 3.0F;
  8. public bool isMoving = false;
  9. public AudioClip step;
  10.  
  11.  
  12. void Update ()
  13. {
  14. Status();
  15. PlayAudio();
  16.  
  17. CharacterController controller = GetComponent<CharacterController>();
  18. transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);
  19. Vector3 forward = transform.TransformDirection(Vector3.forward);
  20. float curSpeed = speed * Input.GetAxis("Vertical");
  21. controller.SimpleMove(forward * curSpeed);
  22.  
  23. }
  24.  
  25. void Status ()
  26. {
  27. float vertical = Input.GetAxis ("Vertical");
  28.  
  29. if(vertical == 0.0F)
  30. {
  31. isMoving = false;
  32. }
  33.  
  34. else if(vertical != 0.0F)
  35. {
  36. isMoving = true;
  37. }
  38. }
  39.  
  40. void PlayAudio ()
  41. {
  42. if (isMoving == true)
  43. {
  44. audio.clip = step;
  45. audio.Play ();
  46. Debug.Log ("loop-uuuuhhhh!");
  47. }
  48. if (isMoving == false)
  49. {
  50. audio.Stop();
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement