- Home /
Make a spawn point
I want to make a spawn point for my character. A function that will make him spawn when he dies and something else when the level is won How can i do something like this? Please HELP!
Answer by ByteSheep · Dec 05, 2011 at 04:01 AM
To make a spawn point just create an empty game object and position it where you want your player to be spawned. You then need to add a script to the player that sets the variable "respawn"(can be called anything) to true when his life points are down to zero. I don't really know how you're determining wether the player has died, but I am assuming you used life points.. It could look something like this:
var SpawnPoint : Transform;
var respawn : boolean = false;
var PlayerLife : int;
function Update () {
if(PlayerLife <= 0)
{
respawn = true;
}
else
{
respawn = false;
}
if(respawn)
{
transform.position = SpawnPoint.position;
}
}
You will have to add the game object you created before (spawn point) to the slot called "SpawnPoint" in the inspector window. This is a very basic script that will send your player to the position of the respawn point as soon as his life points reach zero. This should help you get a simple respawn which you can customise to your needs, hope it helped!
Cheers mate but tell me something...inspector window is this line of the code? transform.position = SpawnPoint.position; So I have to add (lets say the cube to this line?)How do i do this?(i'm really low but i hope i'm gonna learn) Ty very much for making this script. Hope you can answer my question if it's not to dumb. Ty
The inspector window is not part of the code but is ins$$anonymous$$d a part of the unity layout - you have game/scene view, your project, your hierarchy, and then your Inspector. The Inspector is normally situated on the right of the unity layout I think. All 'parts' of the interface are labeled though: hierarchy, inspector etc. When you click on your player (player should be in the hierarchy), then the Inspector should show you the script component.. That is where you should see a slot named Spawn Point and that is where you can drag the spawn point game object. So to sum up: Click on your player in the hierarchy section and then look at the inspector (should be on right side), if the player has not got the script attached yet then you'll have to drag the script (above) into the inspector - which should create a script component in the inspector. That script component should have a 'slot' named Spawn Point where you can select (or drag) a game object from your hierarchy section, in this case needing to be your spawn point game object. Here's an image of the inspector, hierarchy and project section: http://www.scriptocalypse.com/wp-content/uploads/2011/10/unityEditorScriptSample2_3.png Hope it helped understand it!
Is this C# or JavaScript? I'm trying to implement the code using C#.
Okay, @ByteSheep ,but how would be written if you need to respawn after touching something?
Your answer
![](https://koobas.hobune.stream/wayback/20220613061754im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Spawning script error 0 Answers
Why Does My GameObject Not Spawn Anymore? 2 Answers
Spawning objects help 2 Answers