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

using UnityEngine;
using System.Collections;
public class player2_controls : MonoBehaviour {
public Animator animator;
void Start () {
}
public float speed;
public Vector2 jumpVector;
public GameObject bullet;
bool canJump = true;
void Update() {
Vector2 velo = rigidbody2D.velocity;
velo.x = Input.GetAxis ("Horizontal_P2") * speed;
rigidbody2D.velocity = velo;
animator.SetFloat("Velocity",velo.magnitude);
animator.SetBool ("Fall", !canJump);
applyPlayerDirection (Input.GetAxisRaw ("Horizontal_P2"));
if (Input.GetKey (KeyCode.W)){
if (canJump == true){
rigidbody2D.velocity = jumpVector;
canJump = false;
}
}
//if (Input.GetKey (KeyCode.Space)){
//shoot
//GameObject bulletGO = Instantiate (bullet) as GameObject;
//bulletGO.transform.posplayteition = transform.position;
//}
}
//Changes direction of sprite according to key pressed
private void applyPlayerDirection(float moveHorizontal)
{
if (moveHorizontal != 0)
{
Vector3 scale = transform.localScale;
scale.x = moveHorizontal * Mathf.Abs(scale.x);
transform.localScale = scale;
}
}
void OnCollisionEnter2D(Collision2D col){
if (col.collider.tag == "ground")
canJump = true;
else if(col.collider.tag == "Player")
canJump = true;
}
}