- Home /
simple checkpoint/save/load system in javascript
In my game I would like to setup a system where if the player dies it will take them back to the position they were before they died and the walls rotated in the position they were before death since the premise of the game is to rotate walls to get from point a to b. For the save and load system I wanted to make it so the player can save at the end of a stage and load the beginning of a level if they leave/quit the game. I'm working in javascript. If anyone could help with that it would be apperciated.
Answer by fafase · Aug 09, 2012 at 07:18 AM
http://answers.unity3d.com/questions/8480/how-to-scrip-a-saveload-game-option.html
or
http://docs.unity3d.com/Documentation/ScriptReference/PlayerPrefs.html
for saving game.
Now for the respawn of the player. Place some trigger boxes around the level where you want to checkpoint add this.
On the player add a variable:
var checkpointPosition:Vector3;
On the trigger boxes
var player:PlayerScript;
function Start(){
player = GameObject.Find("Player").GetComponent(PlayerScript);}
function OnTriggerEnter(other:Collider){
if(other.gameObject.tag=="Player"){
player.checkpointPosition = transform.position;}
}
When the player enters the box, the box position is assigned to the variable.
Now back on the player:
function Start(){
checkpointPosition=Vector3(0,0,0);}
function Update(){
if(health<=0)transform.position = checkpointPosition;
}
I assume your player start at 0,0,0 but obviously you know what to do. If your player reaches 0 for health, he is sent to checkpointPosition.
Answer by medi88 · Apr 25, 2013 at 12:49 AM
pleez i want to ask . i have the same problem as u and i wante to use Application.LoadLevel(); when the player die . and respown in the position of last chek points ( use application.loadlevel to make my enemys disappertre) can i use it with the chek points??
Your answer
Follow this Question
Related Questions
Saving lots of objects (Only answer in JavaScript) 1 Answer
Trying to save/load game, codes doesnt do anything. not even an error. 1 Answer
Scene Saving 1 Answer
checkpoint level please 2 Answers
half life save/load system ? 1 Answer