Browse Source

Death timer working (black hearts). Time for weeds and some almost expired beef schnitzel, it was real cheap but expired today.

master
Lachlan 9 years ago
parent
commit
f3a6df06b0
2 changed files with 51 additions and 26 deletions
  1. BIN
      playable/Assets/Scenes/Level1.unity
  2. +51
    -26
      playable/Assets/Scripts/playerController.cs

BIN
playable/Assets/Scenes/Level1.unity View File


+ 51
- 26
playable/Assets/Scripts/playerController.cs View File

@ -49,7 +49,10 @@ public class playerController : MonoBehaviour {
private bool stopDash = false; private bool stopDash = false;
public float deathTimer = 3.0f; public float deathTimer = 3.0f;
bool droppedCandy = false; bool droppedCandy = false;
public bool heartBlack = false;
public bool heartColor = true;
public bool dead = false;
public float heartTimer = 0.0f;
@ -152,6 +155,12 @@ public class playerController : MonoBehaviour {
heartCanister.transform.position = heartPos; heartCanister.transform.position = heartPos;
hearts.Add(heartCanister); //adds heart to list hearts.Add(heartCanister); //adds heart to list
if (heartBlack == true && heartColor == false){
heartCanister.guiTexture.color = Color.black;
//else (heartCanister.guiTexture.color = Color.red);
}
}//end for }//end for
displayedHealth = health; displayedHealth = health;
@ -164,32 +173,48 @@ public class playerController : MonoBehaviour {
private void death() private void death()
{ {
if (health <= 0) if (health <= 0|| dead ==true) {
if (deathTimer > 0) dead = true;
{ if (dead == true){
deathTimer -=Time.deltaTime; heartColor = false;
if (!droppedCandy){ heartBlack = true;
Instantiate (newCandy, transform.position + Vector3.up, transform.rotation); heartTimer += Time.deltaTime;
droppedCandy = true; if (heartTimer >=1.5f){
health = 1;
}
if (heartTimer >=2.5f){
health = 2;
}
} }
transform.position = new Vector3 (0,-50,0); if (deathTimer > 0) {
//gameObject.active = false; deathTimer -= Time.deltaTime;
if (!droppedCandy) {
if(deathTimer <=0) Instantiate (newCandy, transform.position + Vector3.up, transform.rotation);
{ droppedCandy = true;
//gameObject.active = true; }
transform.position = new Vector3 (0, -50, 0);
if (deathTimer <= 0) {
Vector3 spawnPos = new Vector3 (Random.Range (-20.0f, 20.0f), 15.0f, 0); //picks random position Vector3 spawnPos = new Vector3 (Random.Range (-20.0f, 20.0f), 15.0f, 0); //picks random position
health = 3; //resets life health = 3; //resets life
transform.position = spawnPos; //changes position transform.position = spawnPos; //changes position
rigidbody2D.velocity = Vector2.zero; rigidbody2D.velocity = Vector2.zero;
deathTimer = deathTimer + 3.02f; deathTimer = deathTimer + 3.02f;
droppedCandy = false; heartTimer = heartTimer - 3.00f;
droppedCandy = false;
} heartBlack = false;
}//end if dead = false;
}//end death heartColor = true;
}
}//end if
/*else if (hearts <= 0) {
dead = true;
}*/
}//end death
}
private void applyPlayerDirection(float moveHorizontal) private void applyPlayerDirection(float moveHorizontal)
{ {

|||||||
x
 
000:0
Loading…
Cancel
Save