- Home /
This question was
closed Jul 14, 2013 at 12:58 AM by
fafase for the following reason:
The question is answered, right answer was accepted
Question by
SpeedTutor · Jul 14, 2013 at 12:50 AM ·
javascriptguinothing
If "x" then do nothing?
This might be the most poorly designed script but is there anyway to stop the script from doing anything at a certain point? As I want to stop the script when health reaches the maximum value of 100.
#pragma strict
var tex1 : Texture;
var tex2 : Texture;
var tex3 : Texture;
var tex4 : Texture;
var health : float;
private var enterCollider : boolean = false;
//Damage collider
function OnTriggerEnter (Col : Collider)
{
if(Col.gameObject.tag == "Player")
{
enterCollider = true;
}
}
//Normal state
function OnTriggerExit (Col : Collider)
{
if(Col.gameObject.tag == "Player")
{
enterCollider = false;
}
}
function Start()
{
//Initial Health
health = 100;
}
function Update()
{
//Health countdown whilst in damage collider
if(health > 0 && enterCollider == true)
{
health -= Time.deltaTime;
}
//normal health regeneration
if(health > 0 && enterCollider == false)
{
health += Time.deltaTime;
}
//When health reaches 100 again, do nothing?
if(health == 100 && enterCollider = false)
{
//Do Nothing?
}
}
function OnGUI()
{
if (health <= 100)
{
GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height), tex1);
}
if (health <= 90)
{
GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height), tex2);
}
if (health <= 80)
{
GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height), tex3);
}
if (health <= 70)
{
GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height), tex4);
}
}
Comment
Ignore this post, I thought about it a little and found my own solution.
//added
var maxHealth
if(health > maxHealth)
{
health = maxHealth;
}