- Home /
Respawn Script activating once the player is dead
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 you see I've created a simple respawn script where the player will enter a trigger which simple then transports the players from his/hers current position and places then back to there original spawn point. The script is as following.....
var startPosition : Transform;
function OnTriggerEnter(theCollider : Collider)
{
theCollider.transform.position = startPosition.position;
}
Now the problem I'm having is that I'm using a simple health system that I obtain on the Unity Asset store (Grid Digital - Simple Health System), if you having seen it before the script that pretty much handlys the players health is a 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;
}
}
Now I am aware that it actually just changes the GUI health texture, but that is simple all I need it to do. My problem is though that I went to be able create an if statement that pretty much says that if the player losses all his health (texture health) then the respawn script kicks in sending the player back to his original position and then resets the health script so it looks like the player has all his/her health back.
Before anyone says, just figure it out for yourself, I am not looking for anyone to just write the script for me (though if anyone wants to that would be great) I wondering how you go around doing this so that I can learn more about scripting.
If anyone can help, tutorials, links, etc. that would be extremely helpfully.
Go dtí an chéad uair eile, slán leat
Answer by sparkzbarca · Jan 22, 2013 at 12:18 AM
if(Hearts =< 0)
{
player.transform.position = startPosition;
guiTexture.texture = FourHearts;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613091347im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
,Can i use InvokeRepeating to spawn just 1 GameObject at a time? 1 Answer
Problem Spawning Enemys with Health. 2 Answers
Instantiate on value change 2 Answers
Instantiate on value change 4 Answers
Player Respawn After Death 1 Answer