x


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.

more ▼

asked Aug 09 '12 at 05:47 AM

avalon45 gravatar image

avalon45
1 1 2 2

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Aug 09 '12 at 07:18 AM

fafase gravatar image

fafase
10.5k 9 15 40

Thanks alot

Aug 09 '12 at 03:54 PM avalon45
(comments are locked)
10|3000 characters needed characters left

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??

more ▼

answered Apr 25 at 12:49 AM

medi88 gravatar image

medi88
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3446
x436
x434
x204
x37

asked: Aug 09 '12 at 05:47 AM

Seen: 1028 times

Last Updated: Apr 25 at 05:11 PM