Browse Source

Added Health bar + landing on player will remove heart

weapons
Joshua Reason 9 years ago
parent
commit
2803b75aae
10 changed files with 119 additions and 3 deletions
  1. BIN
      playable/Assets/Heart 1.prefab
  2. +4
    -0
      playable/Assets/Heart 1.prefab.meta
  3. BIN
      playable/Assets/Heart.png
  4. +47
    -0
      playable/Assets/Heart.png.meta
  5. BIN
      playable/Assets/Heart.prefab
  6. +4
    -0
      playable/Assets/Heart.prefab.meta
  7. BIN
      playable/Assets/Lachlan_jump_work.unity
  8. +33
    -1
      playable/Assets/Scripts/PlayerControler.cs
  9. +31
    -2
      playable/Assets/Scripts/player2_controls.cs
  10. BIN
      playable/ProjectSettings/TagManager.asset

BIN
playable/Assets/Heart 1.prefab View File


+ 4
- 0
playable/Assets/Heart 1.prefab.meta View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 0d389d1b38821bf42927835a245fcbfc
NativeFormatImporter:
userData:

BIN
playable/Assets/Heart.png View File

Before After
Width: 23  |  Height: 24  |  Size: 1.1 KiB

+ 47
- 0
playable/Assets/Heart.png.meta View File

@ -0,0 +1,47 @@
fileFormatVersion: 2
guid: e1474e33244f9b940b641e1d2f515f84
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 1024
textureSettings:
filterMode: -1
aniso: 16
mipBias: -1
wrapMode: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 1
alphaIsTransparency: 1
textureType: 8
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:

BIN
playable/Assets/Heart.prefab View File


+ 4
- 0
playable/Assets/Heart.prefab.meta View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: dd2f67d649876c549bbdec2deadaa076
NativeFormatImporter:
userData:

BIN
playable/Assets/Lachlan_jump_work.unity View File


+ 33
- 1
playable/Assets/Scripts/PlayerControler.cs View File

@ -11,7 +11,11 @@ public class PlayerControler : 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 PlayerControler : MonoBehaviour {
animator.SetBool ("Fall", !canJump);
applyPlayerDirection (Input.GetAxisRaw ("Horizontal_P1"));
if (displayedHealth != health) {
updateHealth = true;
}
if (updateHealth)
displayHealth (health);
if (Input.GetKey (KeyCode.UpArrow)){
if (canJump == true){
@ -39,6 +49,20 @@ public class PlayerControler : MonoBehaviour {
//}
}
private void displayHealth(int health){
GameObject[] hearts = GameObject.FindGameObjectsWithTag("heartUI2");
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 (1-(i * 0.033f), 0.95f, 0);
heartCanister.transform.position = heartPos;
}
displayedHealth = health;
updateHealth = false;
}
private void applyPlayerDirection(float moveHorizontal)
{
if (moveHorizontal != 0)
@ -52,8 +76,16 @@ public class PlayerControler : MonoBehaviour {
void OnCollisionEnter2D(Collision2D col){
if (col.collider.tag == "ground")
canJump = true;
else if(col.collider.tag == "Player")
else if (col.collider.tag == "Player") {
canJump = true;
if(transform.position.y>col.transform.position.y){
col.gameObject.GetComponent<player2_controls>().health --;
//health --;
rigidbody2D.velocity = jumpVector;
canJump = false;
}
}
}
}

+ 31
- 2
playable/Assets/Scripts/player2_controls.cs View File

@ -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;
}
}
}

BIN
playable/ProjectSettings/TagManager.asset View File


Loading…
Cancel
Save