Hi there i am busy working on this script and i am hoping it is going to get advanced so i can use it in many other games i am working on.
The problem is i want the script to know when it has hit something then if it hit something again within a certain amount of time to reset the time it takes to start regenerating health. I Would really appreciate the help guys thanks!
Here’s the script
var health : int = 100;
var lives : int = 3;
var normalHealth : boolean = true;
var healthRegen100 : boolean = false;
var healthEasyMode300 : boolean = false;
var healthNorMode100 : boolean = false;
var healthHardMode50 : boolean = false;
var healthRegenaration : boolean = true;
var healthRegenerationTime : int = 10;
var healthRegenerationTimeReset : int;
var loseHealthTag1_5health : String;// In the inspector just type the name of the Tag you want to be affected by // TRY AN ARRAY IN HERE [] !!!!!!!!!!!!!!!!!!!!!!!
var loseHealthTag2_10health : String;
var loseHealthTag3_15health : String;
var loseHealthTag4_20health : String;
var loseHealthTag5_25health : String;// In the inspector just type the name of the Tag you want to be affected by
var loseHealthTag6_30health : String;
var loseHealthTag7_35health : String;
var loseHealthTag8_40health : String;
var loseHealthTag9_45health : String;// In the inspector just type the name of the Tag you want to be affected by
var loseHealthTag10_50health : String;
@HideInInspector var gotHit : boolean = false;
@HideInInspector var gotHitAgain : boolean = false;
function Update()
{
Modes();
if(health >= 100 && normalHealth == true)
{
health = 100;
}
}
// EasyMode /////////// EasyMode /////////// EasyMode
function OnTriggerEnter(hit : Collider)
{
if(hit.gameObject.tag == loseHealthTag1_5health && normalHealth == true && healthRegenerationTime <= 10 )
{
health -= 10;
Debug.Log(health);
if(healthRegenaration == true)
{
gotHit = true;
HealthRegenaration();
gotHit = false;
}
}
if(hit.gameObject.tag == loseHealthTag2_10health && normalHealth == true)
{
health -= 20;
Debug.Log(health);
if(healthRegenaration == true)
{
gotHit = true;
HealthRegenaration();
gotHit = false;
}
}
if(hit.gameObject.tag == loseHealthTag3_15health && normalHealth == true)
{
health -= 25;
Debug.Log(health);
if(healthRegenaration == true)
{
gotHit = true;
HealthRegenaration();
gotHit = false;
}
}
if(hit.gameObject.tag == loseHealthTag4_20health && normalHealth == true)
{
health -= 50;
Debug.Log(health);
if(healthRegenaration == true)
{
gotHit = true;
HealthRegenaration();
gotHit = false;
} }
if(health <= 0)
{
lives -= 1;
transform.position = Vector3 (0,10,0);// In here type the Co-ordinates of where you would like to spawn. When you die
health = 100;
}
}
function Modes() // For the Editor
{
if(normalHealth)
{
healthRegen100 = false;
healthEasyMode300 = false;
healthNorMode100 = false;
healthHardMode50 = false;
}
if(healthRegen100)
{
normalHealth = false;
healthEasyMode300 = false;
healthNorMode100 = false;
healthHardMode50 = false;
}
if(healthEasyMode300)
{
healthNorMode100 = false;
healthHardMode50 = false;
normalHealth = false;
healthRegen100 = false;
}
if(healthNorMode100)
{
healthHardMode50 = false;
normalHealth = false;
healthRegen = false;
healthEasyMode300 = false;
}
if(healthHardMode50)
{
normalHealth = false;
healthRegen = false;
healthEasyMode300 = false;
healthNorMode100 = false;
}
}
function HealthRegenaration()
{
if(gotHit == true && healthRegenaration == true);
yield WaitForSeconds (healthRegenerationTime);
health += 10;
yield WaitForSeconds(healthRegenerationTime);