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.

61 lines
1.3 KiB

9 years ago
  1. using UnityEngine;
  2. using System.Collections;
  3. public class player2_controls : MonoBehaviour {
  4. void Start () {
  5. }
  6. bool pushed = false;
  7. public float speed;
  8. public Vector2 jumpVector;
  9. public GameObject bullet;
  10. bool canJump = true;
  11. bool facingRight = true;
  12. float currentSpeed;
  13. float pushtime;
  14. void Update() {
  15. if (!pushed) {
  16. Vector2 velo = rigidbody2D.velocity;
  17. velo.x = (Input.GetAxis ("Horizontal_P2") * speed);
  18. rigidbody2D.velocity = velo;
  19. } else {
  20. Vector2 velo = rigidbody2D.velocity;
  21. if (velo.x < 0.4f && Time.time > pushtime)
  22. pushed = false;
  23. }
  24. if (Input.GetKey (KeyCode.W)){
  25. if (canJump == true){
  26. rigidbody2D.velocity = jumpVector;
  27. canJump = false;
  28. }
  29. }
  30. if (Input.GetKeyDown ("a") && facingRight) {
  31. transform.Rotate (Vector3.up * 180);
  32. facingRight = false;
  33. }
  34. if (Input.GetKeyDown ("d") && !facingRight) {
  35. transform.Rotate (Vector3.up * 180);
  36. facingRight = true;
  37. }
  38. transform.eulerAngles = new Vector3 (transform.eulerAngles.x, transform.eulerAngles.y,0);
  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. public void Pushed(){
  47. pushed = true;
  48. pushtime = Time.time + 0.5f;
  49. }
  50. }