Hello to all, I was wondering if anyone out there on the this wide world of 8 billion people could lend me just a moment of there time and help me out with some scripting problems I’ve being having.
Know firstly before I start I’ve being using the simple health system that I obtain on the Unity Asset store (Grid Digital - Simple Health System) to create a health system. Know I am aware that the way the script works is that when the enemy hits the player a heart will disappear on the player GUI.
In case you’s are not aware of what this script looks like, it 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.
var startPosition : Transform;
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;
//CompareTag ("Player").transform.position = startPosition;
//guiTexture.texture = FourHearts;
}
}
Know I’ve writing a simple respawn script that uses the above script, it is as follows…
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;
CompareTag ("Player").transform.position = startPosition;
guiTexture.texture = FourHearts;
}
}
Furthermore the script seems to work, in the sense that there is no errors, however the player won’t respawn back at his original starting position. I was wondering if someone could look over the script and tell me if there was something wrong with it, any and all help would be great.
Go dtí an chéad uair eile, slán leat