Skip to content
Permalink
6e157e73d6
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
369 lines (336 sloc) 12.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;
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()
{
}
// Update----------------------------------------------------------
void Update ()
{
//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;
}
}
}