|
|
@ -11,7 +11,11 @@ public class player2_controls : MonoBehaviour { |
|
|
|
|
|
|
|
public float speed; |
|
|
|
public Vector2 jumpVector; |
|
|
|
public int health = 0; |
|
|
|
private int displayedHealth = 0; |
|
|
|
private bool updateHealth = false; |
|
|
|
public GameObject bullet; |
|
|
|
public GameObject heart; |
|
|
|
bool canJump = true; |
|
|
|
|
|
|
|
|
|
|
@ -24,6 +28,12 @@ public class player2_controls : MonoBehaviour { |
|
|
|
animator.SetFloat("Velocity",velo.magnitude); |
|
|
|
animator.SetBool ("Fall", !canJump); |
|
|
|
applyPlayerDirection (Input.GetAxisRaw ("Horizontal_P2")); |
|
|
|
|
|
|
|
if (displayedHealth != health) { |
|
|
|
updateHealth = true; |
|
|
|
} |
|
|
|
if (updateHealth) |
|
|
|
displayHealth (health); |
|
|
|
|
|
|
|
if (Input.GetKey (KeyCode.W)){ |
|
|
|
if (canJump == true){ |
|
|
@ -39,6 +49,19 @@ public class player2_controls : MonoBehaviour { |
|
|
|
//}
|
|
|
|
} |
|
|
|
|
|
|
|
private void displayHealth(int health){ |
|
|
|
GameObject[] hearts = GameObject.FindGameObjectsWithTag("heartUI"); |
|
|
|
foreach (GameObject desHeart in hearts) |
|
|
|
GameObject.Destroy (desHeart); |
|
|
|
|
|
|
|
for (int i=1; i<= health; i++) { |
|
|
|
GameObject heartCanister = Instantiate (heart) as GameObject; |
|
|
|
Vector3 heartPos = new Vector3 ((i * 0.033f), 0.95f, 0); |
|
|
|
heartCanister.transform.position = heartPos; |
|
|
|
} |
|
|
|
displayedHealth = health; |
|
|
|
updateHealth = false; |
|
|
|
} |
|
|
|
//Changes direction of sprite according to key pressed
|
|
|
|
private void applyPlayerDirection(float moveHorizontal) |
|
|
|
{ |
|
|
@ -53,8 +76,14 @@ public class player2_controls : MonoBehaviour { |
|
|
|
void OnCollisionEnter2D(Collision2D col){ |
|
|
|
if (col.collider.tag == "ground") |
|
|
|
canJump = true; |
|
|
|
else if(col.collider.tag == "Player") |
|
|
|
canJump = true; |
|
|
|
else if (col.collider.tag == "Player") { |
|
|
|
if(transform.position.y>col.transform.position.y){ |
|
|
|
col.gameObject.GetComponent<PlayerControler>().health --; |
|
|
|
//health --;
|
|
|
|
rigidbody2D.velocity = jumpVector; |
|
|
|
canJump = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|