You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.3 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. public class player2_controls : MonoBehaviour {
  4. public Animator animator;
  5. void Start () {
  6. }
  7. public float speed;
  8. public Vector2 jumpVector;
  9. public GameObject bullet;
  10. bool canJump = true;
  11. void Update() {
  12. Vector2 velo = rigidbody2D.velocity;
  13. velo.x = Input.GetAxis ("Horizontal_P2") * speed;
  14. rigidbody2D.velocity = velo;
  15. animator.SetFloat("Velocity",velo.magnitude);
  16. animator.SetBool ("Fall", !canJump);
  17. applyPlayerDirection (Input.GetAxisRaw ("Horizontal_P2"));
  18. if (Input.GetKey (KeyCode.W)){
  19. if (canJump == true){
  20. rigidbody2D.velocity = jumpVector;
  21. canJump = false;
  22. }
  23. }
  24. //if (Input.GetKey (KeyCode.Space)){
  25. //shoot
  26. //GameObject bulletGO = Instantiate (bullet) as GameObject;
  27. //bulletGO.transform.posplayteition = transform.position;
  28. //}
  29. }
  30. //Changes direction of sprite according to key pressed
  31. private void applyPlayerDirection(float moveHorizontal)
  32. {
  33. if (moveHorizontal != 0)
  34. {
  35. Vector3 scale = transform.localScale;
  36. scale.x = moveHorizontal * Mathf.Abs(scale.x);
  37. transform.localScale = scale;
  38. }
  39. }
  40. void OnCollisionEnter2D(Collision2D col){
  41. if (col.collider.tag == "ground")
  42. canJump = true;
  43. else if(col.collider.tag == "Player")
  44. canJump = true;
  45. }
  46. }