hi, I was wondering if it is possible to make a save area in my game so that I can have a checkpoint and when you walk through it, the game will auto save. Then on the main menu I wanted a load game button that will load from that last checkpoint where you were.
I am not good at scripting at all so a link or the code would be great.
Also I wanted to make a collider with the trigger set to true for the checkpoints.
Thanks in advance
"also is posted in forums"
For the scene saving, have a look at this previous question:
http://answers.unity3d.com/questions/971/how-to-scrip-a-save-load-game-option
For the trigger -
- Create an empty gameObject and
assign a SphereCollider to it.
- Enable the isTrigger property in the
SphereCollider (have a look at the
wiki what triggers are).
-
Assign the following script to your
gameObject:
var player:Collider;
function OnTriggerEnter(other:Collider)
{
Debug.Log(other.transform.name + " has touched the trigger");
if(other == player)
{
Debug.Log("It is the player!");
// Here you save your scene
// SaveYourCheckpoint();
}
}
- Reference your character (FPS or
anything with a rigidbody collider)
to the player variable in this
script.
- If your character now walks into the
trigger area, it should cause two
messages: "XYZ has touched the
trigger" and "It is the player!".
For your load button, refer this.
(code is untested, but I think it should work)