Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class FPS : MonoBehaviour
- {
- public float speed = 3.0F;
- public float rotateSpeed = 3.0F;
- public bool isMoving = false;
- public AudioClip step;
- void Update ()
- {
- Status();
- PlayAudio();
- CharacterController controller = GetComponent<CharacterController>();
- transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);
- Vector3 forward = transform.TransformDirection(Vector3.forward);
- float curSpeed = speed * Input.GetAxis("Vertical");
- controller.SimpleMove(forward * curSpeed);
- }
- void Status ()
- {
- float vertical = Input.GetAxis ("Vertical");
- if(vertical == 0.0F)
- {
- isMoving = false;
- }
- else if(vertical != 0.0F)
- {
- isMoving = true;
- }
- }
- void PlayAudio ()
- {
- if (isMoving == true)
- {
- audio.clip = step;
- audio.Play ();
- Debug.Log ("loop-uuuuhhhh!");
- }
- if (isMoving == false)
- {
- audio.Stop();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement