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;
public float deathTimer = 3.0f;
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;
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
displayedHealth = health;
@ -164,32 +173,48 @@ public class playerController : MonoBehaviour {
private void death()
{
if (health <= 0)
if (deathTimer > 0)
{
deathTimer -=Time.deltaTime;
if (!droppedCandy){
Instantiate (newCandy, transform.position + Vector3.up, transform.rotation);
droppedCandy = true;
if (health <= 0|| dead ==true) {
dead = true;
if (dead == true){
heartColor = false;
heartBlack = true;
heartTimer += Time.deltaTime;
if (heartTimer >=1.5f){
health = 1;
}
if (heartTimer >=2.5f){
health = 2;
}
}
transform.position = new Vector3 (0,-50,0);
//gameObject.active = false;
if(deathTimer <=0)
{
//gameObject.active = true;
Vector3 spawnPos = new Vector3 (Random.Range (-20.0f, 20.0f), 15.0f, 0); //picks random position
health = 3; //resets life
transform.position = spawnPos; //changes position
rigidbody2D.velocity = Vector2.zero;
deathTimer = deathTimer + 3.02f;
droppedCandy = false;
}
}//end if
}//end death
if (deathTimer > 0) {
deathTimer -= Time.deltaTime;
if (!droppedCandy) {
Instantiate (newCandy, transform.position + Vector3.up, transform.rotation);
droppedCandy = 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
health = 3; //resets life
transform.position = spawnPos; //changes position
rigidbody2D.velocity = Vector2.zero;
deathTimer = deathTimer + 3.02f;
heartTimer = heartTimer - 3.00f;
droppedCandy = false;
heartBlack = false;
dead = false;
heartColor = true;
}
}//end if
/*else if (hearts <= 0) {
dead = true;
}*/
}//end death
}
private void applyPlayerDirection(float moveHorizontal)
{

Loading…
Cancel
Save