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.

42 lines
869 B

  1. using UnityEngine;
  2. using System.Collections;
  3. public class PlayerControler : MonoBehaviour {
  4. // Use this for initialization
  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_P1") * speed;
  14. rigidbody2D.velocity = velo;
  15. if (Input.GetKey (KeyCode.UpArrow)){
  16. if (canJump == true){
  17. rigidbody2D.velocity = jumpVector;
  18. canJump = false;
  19. }
  20. }
  21. //if (Input.GetKey (KeyCode.Space)){
  22. //shoot
  23. //GameObject bulletGO = Instantiate (bullet) as GameObject;
  24. //bulletGO.transform.position = transform.position;
  25. //}
  26. }
  27. void OnCollisionEnter2D(Collision2D col){
  28. if (col.collider.tag == "ground")
  29. canJump = true;
  30. else if(col.collider.tag == "Player")
  31. canJump = true;
  32. }
  33. }