- Home /
checkpoint question????
how can i make chekpoint system in unity. like when player touch 1st check point collider then die so he re spawn at 1st check point position if the the player touch 2nd check point & then die so, he re spawn at 2nd check point position
so, basically how to store these information in the script
thanks in advance
Answer by David O'Donoghue · May 24, 2010 at 07:33 AM
On your player add a public variable
public Collider currentCheckPoint;
Then create empty game objects with a box collider set to "Trigger" and create a script like this, make sure you replace "PlayerScript" with the name of your player's main control script and "Playerobject" with the name of your players gameobject.
void OnTriggerEnter() {
PlayerScript myPlayer = (PlayerScript) GameObject.Find("Playerobject").GetComponent("PlayerScript");
myPlayer.currentCheckPoint = this;
}
Now you can find out where the check point is when he dies and move the player.
Inside the player's script you can have a function like this:
void PlayerDied() {
this.transform.position = currentCheckPoint.position;
}
hey thanks david but the problem is i am using java script how can i convert this script in java
Hey Apexuni, your going to need to learn how to translate between these two computer languages to get the most out of this forum. Also, Javascript and Java are two entirely different languages.
i have a problem in your script david it tell me this error i need help please
Assets/checkpoint.cs(3,7): error CS0246: The type or namespace name `Path' could not be found. Are you missing a using directive or an assembly reference?
Answer by spinaljack · May 24, 2010 at 09:55 AM
http://unity3d.com/support/resources/tutorials/3d-platform-game
This tutorial has exactly what you need, a set of check points that are activated and deactivated as you walk over them. Just read the tutorial and lift the code from the resources.
Answer by GameRocker · Jan 25, 2013 at 05:31 PM
A Video Is Made By Me On Same Topic! Link Of Video Is http://youtu.be/blzoX2guK2s
You Should Also Search For Saving Scene By Script This Might Also Help You! I Am Working On It.
This is extremely unhelpful, and it's clearly not an answer, and this is an incredibly old topic, and you double-posted.
Sorry But The Others Who Came Here For Help $$anonymous$$ay Find This Useful.
@gameRocker your videos in such low quality nobody can read your code and you should always post your code in the info of the video just in case..
saving scene by script? I will take a look at it.
Answer by dre38w · Nov 09, 2010 at 04:48 PM
Javascript? Try this.
private var originalSpawn : boolean = true; private var respawn2 : boolean; private var respawn1 : boolean;
function OnTriggerEnter(other : Collider) { //You'll have to make a death script and make a boolean true false command. if (dead == true) { if (originalSpawn == true) { //Put your coordinates of the original spawn point. transform.position = Vector3(x, y, z); } }
if (other.gameObject.tag == "Checkpoint1") { originalSpawn = false; respawn1 = true; respawn2 = false; }
if (respawn1 == true) { if (dead == true) { //Put your coordinates of the spawn point. transform.position = Vector3(x, y, z); } }
if (other.gameObject.tag == "Checkpoint2") { originalSpawn = false; respawn2 = true; respawn1 = false; }
if (respawn2 == true) { if (dead == true) { //Put your coordinates of the spawn point. transform.position = Vector3(x, y, z); } } }
Hopefully this works.
and did there have to told what dead is like: var dead : Transform; or something without and explain for the unity it is marked as a error
Answer by santiandrade · Nov 19, 2015 at 12:29 PM
I explain how to create a checkpints system in my blog: https://santiandrade.github.io/Unity-Creating-a-checkpoints-system/
Good luck!
That's C Sharp who likes it?? Java script is what i'm here for -.-''
thanks im using c# and this was a big help however there seems to be an issue with GetComponent in the newer versions please let me know of any fixes
Your answer
![](https://koobas.hobune.stream/wayback/20220613021537im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Saving Game no only player position 2 Answers
checkpoint 1 Answer
Following the next item in an array 0 Answers
How to check if point is inside collider? 1 Answer
Checkpoint script? 1 Answer