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.
 
 
 
 
 

62 lines
1.3 KiB

using UnityEngine;
using System.Collections;
public class PlayerControler : MonoBehaviour {
void Start () {
}
bool pushed = false;
public float speed;
public Vector2 jumpVector;
public GameObject bullet;
bool canJump = true;
bool facingLeft = true;
float currentSpeed;
float pushtime;
void Update() {
if (!pushed) {
Vector2 velo = rigidbody2D.velocity;
velo.x = (Input.GetAxis ("Horizontal_P1") * speed);
rigidbody2D.velocity = velo;
} else {
Vector2 velo = rigidbody2D.velocity;
if (velo.x < 0.4f && Time.time > pushtime)
pushed = false;
}
if (Input.GetKey (KeyCode.UpArrow)){
if (canJump == true){
rigidbody2D.velocity = jumpVector;
canJump = false;
}
}
if (Input.GetKeyDown ("RightArrow") && facingLeft) {
transform.Rotate (Vector3.up * 180);
facingLeft = false;
}
if (Input.GetKeyDown ("LeftArrow") && !facingLeft) {
transform.Rotate (Vector3.up * 180);
facingLeft = 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;
}
}