Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerInput : MonoBehaviour
  6. {
  7.  
  8. private Rigidbody2D rb2d;
  9. private int speed = 1;
  10. private Animator anim;
  11. private bool shoot;
  12.  
  13. // Use this for initialization
  14. void Start ()
  15. {
  16. rb2d = GetComponent<Rigidbody2D> ();
  17. anim = GetComponent<Animator> ();
  18. }
  19.  
  20. // Update is called once per frame
  21. void Update ()
  22. {
  23.  
  24. float y = Input.GetAxisRaw ("Vertical");
  25. float x = Input.GetAxisRaw ("Horizontal");
  26.  
  27. Vector2 input = new Vector2 (x, y);
  28. input.Normalize ();
  29.  
  30. rb2d.velocity = input * speed;
  31. if (input.x == 0 && input.y == 0) {
  32. anim.SetBool ("moving", false);
  33.  
  34. } else {
  35. anim.SetBool ("moving", true);
  36.  
  37. float angle = Mathf.Atan2 (input.y, input.x) * Mathf.Rad2Deg + 90;
  38. angle = Mathf.Round (angle);
  39. transform.rotation = Quaternion.AngleAxis (angle, Vector3.forward);
  40.  
  41. }
  42.  
  43. shootInput();
  44.  
  45.  
  46. }
  47. private void Shooting()
  48. {
  49. if (shoot)
  50. {
  51. anim.SetTrigger("shooting");
  52. }
  53. }
  54.  
  55. private void shootInput()
  56. {
  57. if (Input.GetKeyDown(KeyCode.Space))
  58. {
  59. shoot = true;
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement