Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour
  6. {
  7. public AudioSource audioS;
  8.  
  9. CharacterController charControl;
  10. public float walkSpeed = 4.0f;
  11.  
  12. void Start()
  13. {
  14. charControl = GetComponent<CharacterController>();
  15. }
  16.  
  17. void Update()
  18. {
  19. MovePlayer();
  20. PlayAS();
  21. }
  22.  
  23. void MovePlayer()
  24. {
  25. float horiz = Input.GetAxis("Horizontal");
  26. float vert = Input.GetAxis("Vertical");
  27.  
  28. Vector3 moveDirSide = transform.right * horiz * walkSpeed;
  29. Vector3 moveDirForward = transform.forward * vert * walkSpeed;
  30.  
  31. charControl.SimpleMove(moveDirSide);
  32. charControl.SimpleMove(moveDirForward);
  33.  
  34. }
  35. private void PlayAS()
  36. {
  37. if (charControl.isGrounded == true && charControl.velocity.magnitude> 2f && audioS.isPlaying == false)
  38. {
  39. audioS.volume = Random.Range(0.4f, 0.5f);
  40. audioS.pitch = Random.Range(0.8f, 0.9f);
  41. audioS.Play();
  42.  
  43. }
  44. if(charControl.isGrounded == true && charControl.velocity.magnitude < 2f)
  45. {
  46. audioS.Stop();
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement