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.

44 lines
836 B

  1. using UnityEngine;
  2. using System.Collections;
  3. public class player2_controls : MonoBehaviour {
  4. void Start () {
  5. }
  6. public float speed;
  7. public Vector2 jumpVector;
  8. public GameObject bullet;
  9. bool canJump = true;
  10. void Update() {
  11. Vector2 velo = rigidbody2D.velocity;
  12. velo.x = Input.GetAxis ("Horizontal_P2") * speed;
  13. rigidbody2D.velocity = velo;
  14. if (Input.GetKey (KeyCode.W)){
  15. if (canJump == true){
  16. rigidbody2D.velocity = jumpVector;
  17. canJump = false;
  18. }
  19. }
  20. //if (Input.GetKey (KeyCode.Space)){
  21. //shoot
  22. //GameObject bulletGO = Instantiate (bullet) as GameObject;
  23. //bulletGO.transform.position = transform.position;
  24. //}
  25. }
  26. void OnCollisionEnter2D(Collision2D col){
  27. if (col.collider.tag == "ground")
  28. canJump = true;
  29. else if(col.collider.tag == "Player")
  30. canJump = true;
  31. }
  32. }