Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerInput : MonoBehaviour
- {
- private Rigidbody2D rb2d;
- private int speed = 1;
- private Animator anim;
- private bool shoot;
- // Use this for initialization
- void Start ()
- {
- rb2d = GetComponent<Rigidbody2D> ();
- anim = GetComponent<Animator> ();
- }
- // Update is called once per frame
- void Update ()
- {
- float y = Input.GetAxisRaw ("Vertical");
- float x = Input.GetAxisRaw ("Horizontal");
- Vector2 input = new Vector2 (x, y);
- input.Normalize ();
- rb2d.velocity = input * speed;
- if (input.x == 0 && input.y == 0) {
- anim.SetBool ("moving", false);
- } else {
- anim.SetBool ("moving", true);
- float angle = Mathf.Atan2 (input.y, input.x) * Mathf.Rad2Deg + 90;
- angle = Mathf.Round (angle);
- transform.rotation = Quaternion.AngleAxis (angle, Vector3.forward);
- }
- shootInput();
- }
- private void Shooting()
- {
- if (shoot)
- {
- anim.SetTrigger("shooting");
- }
- }
- private void shootInput()
- {
- if (Input.GetKeyDown(KeyCode.Space))
- {
- shoot = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement