using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class player2_controls : MonoBehaviour {
|
|
|
|
void Start () {
|
|
}
|
|
|
|
bool pushed = false;
|
|
public float speed;
|
|
public Vector2 jumpVector;
|
|
public GameObject bullet;
|
|
bool canJump = true;
|
|
bool facingRight = true;
|
|
float currentSpeed;
|
|
float pushtime;
|
|
|
|
void Update() {
|
|
if (!pushed) {
|
|
Vector2 velo = rigidbody2D.velocity;
|
|
velo.x = (Input.GetAxis ("Horizontal_P2") * speed);
|
|
rigidbody2D.velocity = velo;
|
|
} else {
|
|
Vector2 velo = rigidbody2D.velocity;
|
|
if (velo.x < 0.4f && Time.time > pushtime)
|
|
pushed = false;
|
|
}
|
|
|
|
if (Input.GetKey (KeyCode.W)){
|
|
if (canJump == true){
|
|
rigidbody2D.velocity = jumpVector;
|
|
canJump = false;
|
|
}
|
|
}
|
|
|
|
if (Input.GetKeyDown ("a") && facingRight) {
|
|
transform.Rotate (Vector3.up * 180);
|
|
facingRight = false;
|
|
}
|
|
|
|
if (Input.GetKeyDown ("d") && !facingRight) {
|
|
transform.Rotate (Vector3.up * 180);
|
|
facingRight = true;
|
|
}
|
|
|
|
transform.eulerAngles = new Vector3 (transform.eulerAngles.x, transform.eulerAngles.y,0);
|
|
|
|
}
|
|
|
|
void OnCollisionEnter2D(Collision2D col){
|
|
if (col.collider.tag == "ground")
|
|
canJump = true;
|
|
else if(col.collider.tag == "Player")
|
|
canJump = true;
|
|
}
|
|
|
|
public void Pushed(){
|
|
pushed = true;
|
|
pushtime = Time.time + 0.5f;
|
|
}
|
|
|
|
}
|