Skip to content
Permalink
399042d8ea
Go to file
 
 
Cannot retrieve contributors at this time
397 lines (360 sloc) 13.6 KB
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
//healthbars----------------
public GameObject healthbar1;
public GameObject healthbar2;
public GameObject healthbar3;
public GameObject healthbar4;
public GameObject healthbar5;
public GameObject healthbar6;
public GameObject healthbar7;
public GameObject healthbar8;
public GameObject healthbar9;
public GameObject healthbar10;
//Shield Bars -------------------
public GameObject shieldbar1;
public GameObject shieldbar2;
public GameObject shieldbar3;
public GameObject shieldbar4;
public GameObject shieldbar5;
public GameObject shieldbar6;
public GameObject shieldbar7;
public GameObject shieldbar8;
public GameObject shieldbar9;
public GameObject shieldbar10;
//Player Position =====================
public Vector3 playerPos;
public Vector3 staticPos;
public float distance;
public int distanceInt;
public int playerHealth = 100;
public int playerShields = 100;
//OnCollision
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "EnemyBullet")
{
switch (playerShields)
{
case 0:
playerHealth = playerHealth - 10;
break;
default:
playerShields = playerShields - 10;
break;
}
}
if (collision.gameObject.tag == "Enemy")
{
switch (playerShields)
{
case 0:
playerHealth = playerHealth - 10;
break;
default:
playerShields = playerShields - 10;
break;
}
}
}
//Start-----------------------------------------------------------
void Start()
{
staticPos = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z);
}
// Update----------------------------------------------------------
void Update ()
{
//Death Condition ----------------------------
if (playerHealth <= 0)
{
Application.LoadLevel(2);
}
//Shield Regen
playerPos = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z);
distance = Vector3.Distance(playerPos, staticPos);
distanceInt = Mathf.RoundToInt(distance);
if (playerShields < 100)
{
if (distanceInt % 10 == 0)
{
playerShields = playerShields + 10;
// staticPos = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z);
staticPos = playerPos;
}
}
//Shield Switch ------------------------------
switch (playerShields)
{
case 0:
shieldbar1.SetActive(false);
shieldbar2.SetActive(false);
shieldbar3.SetActive(false);
shieldbar4.SetActive(false);
shieldbar5.SetActive(false);
shieldbar6.SetActive(false);
shieldbar7.SetActive(false);
shieldbar8.SetActive(false);
shieldbar9.SetActive(false);
shieldbar10.SetActive(false);
break;
case 10:
shieldbar1.SetActive(true);
shieldbar2.SetActive(false);
shieldbar3.SetActive(false);
shieldbar4.SetActive(false);
shieldbar5.SetActive(false);
shieldbar6.SetActive(false);
shieldbar7.SetActive(false);
shieldbar8.SetActive(false);
shieldbar9.SetActive(false);
shieldbar10.SetActive(false);
break;
case 20:
shieldbar1.SetActive(true);
shieldbar2.SetActive(true);
shieldbar3.SetActive(false);
shieldbar4.SetActive(false);
shieldbar5.SetActive(false);
shieldbar6.SetActive(false);
shieldbar7.SetActive(false);
shieldbar8.SetActive(false);
shieldbar9.SetActive(false);
shieldbar10.SetActive(false);
break;
case 30:
shieldbar1.SetActive(true);
shieldbar2.SetActive(true);
shieldbar3.SetActive(true);
shieldbar4.SetActive(false);
shieldbar5.SetActive(false);
shieldbar6.SetActive(false);
shieldbar7.SetActive(false);
shieldbar8.SetActive(false);
shieldbar9.SetActive(false);
shieldbar10.SetActive(false);
break;
case 40:
shieldbar1.SetActive(true);
shieldbar2.SetActive(true);
shieldbar3.SetActive(true);
shieldbar4.SetActive(true);
shieldbar5.SetActive(false);
shieldbar6.SetActive(false);
shieldbar7.SetActive(false);
shieldbar8.SetActive(false);
shieldbar9.SetActive(false);
shieldbar10.SetActive(false);
break;
case 50:
shieldbar1.SetActive(true);
shieldbar2.SetActive(true);
shieldbar3.SetActive(true);
shieldbar4.SetActive(true);
shieldbar5.SetActive(true);
shieldbar6.SetActive(false);
shieldbar7.SetActive(false);
shieldbar8.SetActive(false);
shieldbar9.SetActive(false);
shieldbar10.SetActive(false);
break;
case 60:
shieldbar1.SetActive(true);
shieldbar2.SetActive(true);
shieldbar3.SetActive(true);
shieldbar4.SetActive(true);
shieldbar5.SetActive(true);
shieldbar6.SetActive(true);
shieldbar7.SetActive(false);
shieldbar8.SetActive(false);
shieldbar9.SetActive(false);
shieldbar10.SetActive(false);
break;
case 70:
shieldbar1.SetActive(true);
shieldbar2.SetActive(true);
shieldbar3.SetActive(true);
shieldbar4.SetActive(true);
shieldbar5.SetActive(true);
shieldbar6.SetActive(true);
shieldbar7.SetActive(true);
shieldbar8.SetActive(false);
shieldbar9.SetActive(false);
shieldbar10.SetActive(false);
break;
case 80:
shieldbar1.SetActive(true);
shieldbar2.SetActive(true);
shieldbar3.SetActive(true);
shieldbar4.SetActive(true);
shieldbar5.SetActive(true);
shieldbar6.SetActive(true);
shieldbar7.SetActive(true);
shieldbar8.SetActive(true);
shieldbar9.SetActive(false);
shieldbar10.SetActive(false);
break;
case 90:
shieldbar1.SetActive(true);
shieldbar2.SetActive(true);
shieldbar3.SetActive(true);
shieldbar4.SetActive(true);
shieldbar5.SetActive(true);
shieldbar6.SetActive(true);
shieldbar7.SetActive(true);
shieldbar8.SetActive(true);
shieldbar9.SetActive(true);
shieldbar10.SetActive(false);
break;
case 100:
shieldbar1.SetActive(true);
shieldbar2.SetActive(true);
shieldbar3.SetActive(true);
shieldbar4.SetActive(true);
shieldbar5.SetActive(true);
shieldbar6.SetActive(true);
shieldbar7.SetActive(true);
shieldbar8.SetActive(true);
shieldbar9.SetActive(true);
shieldbar10.SetActive(true);
break;
}
//Health Switch ------------------------------
switch (playerHealth)
{
case 0:
healthbar1.SetActive(false);
healthbar2.SetActive(false);
healthbar3.SetActive(false);
healthbar4.SetActive(false);
healthbar5.SetActive(false);
healthbar6.SetActive(false);
healthbar7.SetActive(false);
healthbar8.SetActive(false);
healthbar9.SetActive(false);
healthbar10.SetActive(false);
break;
case 10:
healthbar1.SetActive(true);
healthbar2.SetActive(false);
healthbar3.SetActive(false);
healthbar4.SetActive(false);
healthbar5.SetActive(false);
healthbar6.SetActive(false);
healthbar7.SetActive(false);
healthbar8.SetActive(false);
healthbar9.SetActive(false);
healthbar10.SetActive(false);
break;
case 20:
healthbar1.SetActive(true);
healthbar2.SetActive(true);
healthbar3.SetActive(false);
healthbar4.SetActive(false);
healthbar5.SetActive(false);
healthbar6.SetActive(false);
healthbar7.SetActive(false);
healthbar8.SetActive(false);
healthbar9.SetActive(false);
healthbar10.SetActive(false);
break;
case 30:
healthbar1.SetActive(true);
healthbar2.SetActive(true);
healthbar3.SetActive(true);
healthbar4.SetActive(false);
healthbar5.SetActive(false);
healthbar6.SetActive(false);
healthbar7.SetActive(false);
healthbar8.SetActive(false);
healthbar9.SetActive(false);
healthbar10.SetActive(false);
break;
case 40:
healthbar1.SetActive(true);
healthbar2.SetActive(true);
healthbar3.SetActive(true);
healthbar4.SetActive(true);
healthbar5.SetActive(false);
healthbar6.SetActive(false);
healthbar7.SetActive(false);
healthbar8.SetActive(false);
healthbar9.SetActive(false);
healthbar10.SetActive(false);
break;
case 50:
healthbar1.SetActive(true);
healthbar2.SetActive(true);
healthbar3.SetActive(true);
healthbar4.SetActive(true);
healthbar5.SetActive(true);
healthbar6.SetActive(false);
healthbar7.SetActive(false);
healthbar8.SetActive(false);
healthbar9.SetActive(false);
healthbar10.SetActive(false);
break;
case 60:
healthbar1.SetActive(true);
healthbar2.SetActive(true);
healthbar3.SetActive(true);
healthbar4.SetActive(true);
healthbar5.SetActive(true);
healthbar6.SetActive(true);
healthbar7.SetActive(false);
healthbar8.SetActive(false);
healthbar9.SetActive(false);
healthbar10.SetActive(false);
break;
case 70:
healthbar1.SetActive(true);
healthbar2.SetActive(true);
healthbar3.SetActive(true);
healthbar4.SetActive(true);
healthbar5.SetActive(true);
healthbar6.SetActive(true);
healthbar7.SetActive(true);
healthbar8.SetActive(false);
healthbar9.SetActive(false);
healthbar10.SetActive(false);
break;
case 80:
healthbar1.SetActive(true);
healthbar2.SetActive(true);
healthbar3.SetActive(true);
healthbar4.SetActive(true);
healthbar5.SetActive(true);
healthbar6.SetActive(true);
healthbar7.SetActive(true);
healthbar8.SetActive(true);
healthbar9.SetActive(false);
healthbar10.SetActive(false);
break;
case 90:
healthbar1.SetActive(true);
healthbar2.SetActive(true);
healthbar3.SetActive(true);
healthbar4.SetActive(true);
healthbar5.SetActive(true);
healthbar6.SetActive(true);
healthbar7.SetActive(true);
healthbar8.SetActive(true);
healthbar9.SetActive(true);
healthbar10.SetActive(false);
break;
case 100:
healthbar1.SetActive(true);
healthbar2.SetActive(true);
healthbar3.SetActive(true);
healthbar4.SetActive(true);
healthbar5.SetActive(true);
healthbar6.SetActive(true);
healthbar7.SetActive(true);
healthbar8.SetActive(true);
healthbar9.SetActive(true);
healthbar10.SetActive(true);
break;
}
}
}
You can’t perform that action at this time.