- Home /
How to get your player to respawn when in void (C#)
Hello
I am creating my first game and i am struggling on how to get my sphere that rolls off the edge of my cube to respawn when it is falling in the void.I would like to know how to respwan using the letter R to respawn my player back at the start of the level.
Thanks -Matthew
Answer by $$anonymous$$ · May 20, 2015 at 07:23 AM
This script should be attached to your Sphere
private void Update()
{
if (Input.GetKeyDown(KeyCode.R))
this.transform.position = RespawnPos; // RespawnPos is Vector3
if (transform.position.y <= SPECIFIC_FALL_HEIGHT) // If CUrrent Y position is lower than SPECIFIC_FALL_HEIGHT, don't let it fall further
this.transform.position = RespawnPos;
}
it does not seem to be working how do i set a specific fall height
Answer by Gardes · Jun 09, 2015 at 07:20 PM
Add this to your player
Vector3 respawn_Pos;
void Start () {
respawn_Pos = transform.position;
}
void Update () {
if (Input.GetKeyDown(KeyCode.R))
transform.position = respawn_Pos;
}
I'm glad you got it ;) $$anonymous$$ark this as the answer then :)
Your answer
Follow this Question
Related Questions
How to refer to run a "void" in one c# script from another to respawn a player 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Why can't I make my character die? 3 Answers