To all the people of the Unity world wide website, if you could give me a moment of your time and help me figure out why my script isn’t working. You see I’ve downloaded a simple health system that I obtain on the Unity Asset store (Grid Digital - Simple Health System) to create a health system, and have being trying to create a scrip that will respawn the player once they lost all there health.
However no matter what I try it doesn’t work, you see I’ve coded a respawn script, and it works perfectly fine.
var startPosition : Transform;
function OnTriggerEnter(theCollider : Collider)
{
theCollider.transform.position = startPosition.position;
}
As you can see the script works, however when I tried to create my own script that states that the player will respawn once he/she loses all his health.
var OneHeart : Texture2D; //These variables contain the textures used for the gui.
var TwoHearts : Texture2D;
var ThreeHearts : Texture2D;
var FourHearts : Texture2D;
var NoHearts : Texture2D;
static var Hearts : int = 4; //This is the amount of hearts the character has.
var startPosition : Transform;
function OnTriggerEnter(theCollider : Collider)
{
if(Hearts < 0)
{
Hearts = 0;
}
else
{
theCollider.transform.position = startPosition.position;
guiTexture.texture = FourHearts;
}
}
For my life I can’t see what is wrong, the script should work fine, but it doesn’t. Additionally the health script form the Simple Health System is as followed…
var OneHeart : Texture2D; //These variables contain the textures used for the gui.
var TwoHearts : Texture2D;
var ThreeHearts : Texture2D;
var FourHearts : Texture2D;
var NoHearts : Texture2D;
static var Hearts : int = 4; //This is the amount of hearts the character has.
function Update (){
if(Hearts == 4){ //These if statements change the Gui Texture based on the static var Hearts.
guiTexture.texture=FourHearts;
}
if(Hearts == 3){
guiTexture.texture=ThreeHearts;
}
if(Hearts == 2){
guiTexture.texture=TwoHearts;
}
if(Hearts == 1){
guiTexture.texture=OneHeart;
}
if(Hearts == 0){
guiTexture.texture=NoHearts;
}
if(Hearts > 4){ //These two if statements keep the static var Hearts within the 0-4 range.
Hearts = 4;
}
if(Hearts < 0){
Hearts = 0;
}
}
I was wondering if anyone could just look over my script and see why it is not working, any help would be great.
Go dtí an chéad uair eile, slán leat