Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. public class Player : MonoBehaviour
  2. {
  3.     public Rigidbody rigidBody;
  4.     public AudioSource audioSource;
  5.     public ParticleSystem flyPartical;
  6.  
  7.     public float rotSpeed;
  8.     public float flySpeed;
  9.  
  10.     // Start is called before the first frame update
  11.     void Start()
  12.     {
  13.         rigidBody.GetComponent<Rigidbody>();
  14.         audioSource.GetComponent<AudioSource>();
  15.     }
  16.  
  17.     // Update is called once per frame
  18.     void Update()
  19.     {
  20.         Lounch();
  21.         Rotation();
  22.     }
  23.  
  24.     void Lounch()
  25.     {
  26.         if (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.W))
  27.         {
  28.             rigidBody.AddRelativeForce(Vector3.up * flySpeed);
  29.             if(audioSource.isPlaying == false)
  30.             {
  31.                 audioSource.Play();
  32.                 flyPartical.Play();
  33.             }
  34.         }
  35.         else
  36.         {
  37.             audioSource.Stop();
  38.             flyPartical.Stop();
  39.         }
  40.     }
  41.  
  42.     void Rotation()
  43.     {
  44.         float rotationSpeed = rotSpeed * Time.deltaTime;
  45.  
  46.         rigidBody.freezeRotation = true;
  47.         if(Input.GetKey(KeyCode.D))
  48.         {
  49.             transform.Rotate(Vector3.forward * rotationSpeed);
  50.         }
  51.         else if(Input.GetKey(KeyCode.A))
  52.         {
  53.             transform.Rotate(-Vector3.forward * rotationSpeed);
  54.         }
  55.     }
  56.  
  57.     public void ButtonUp()
  58.     {
  59.         print("вверх");
  60.         transform.Translate(Vector3.up);
  61.     }
  62.  
  63.     public void ButtonLeft()
  64.     {
  65.         print("влево");
  66.     }
  67.  
  68.     public void ButtonRight()
  69.     {
  70.         print("вправо");
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement