how to create a save point?
ohh okay im sorry what do i mean is “saving their progress in the game”
better if its auto-save just like in any MMORPG (online games), or like those sort of they come up on the corresponding save point in every map
how to create a save point?
ohh okay im sorry what do i mean is “saving their progress in the game”
better if its auto-save just like in any MMORPG (online games), or like those sort of they come up on the corresponding save point in every map
Two words: Unity Serializer. It has an extremely simple guide, and it’s surprisingly simple to setup and use.
You should be more specific, but in general…
By savepoint, do you mean a respawn point or an actual save point that saves game data?
I have an answer for both, but for future reference, you should specify your exact problem, along with any code you are using to attempt to implement it. Fattie’s answer explains the basics, so do as he says and create a trigger collider, but skip the serializer step.
Then follow one of the following two options, based on what you want to do.
OPTION 1: respawn point-
If you want your player to respawn at a certain point, then you should create a variable in the script that controls your player’s death (often the health script) of type Vector3. Then make a script on the respawn point that detects if the player has entered the trigger, and then sets the variable to the transform.position of the respawn point. Something simple like this:
Put this on your death or health script:
static var respawn : Vector3;
And this (Or something similar, based on how your game works)
function MyDeathFunction (){
if(Lives != 0){
Lives--;
transform.position = respawn;
}else{
MyGameOverFunction();
}
}
Then make a simple script like this and put it on your respawn points:
function OnTriggerEnter(){
MyDeathScript.respawn = transform.position;
}
DONE!
OPTION 2: save-game point-
If you want your game to save when your player hits the collider, try the PlayerPrefs class. It is simple and easy to use, but the data types it can store are limited to integers, floating-point values, and strings, so I would recommend finding an algorithm to encode your data as one of these variable types(strings are excellent for this) and save that. If you are looking for a more advanceed saving method, you should look into C# or XML serialization.
IF YOU ARE ATTEMPTING TO SAVE MULTIPLE VARIABLES INSIDE A SINGLE STRING FOR PLAYERPREFS:
A method that I use is to find which variables (GameObjects, meshes, animations cannot be encoded, but their names can and those can be used to find them and use them again. Arrays and Structs must be seperated, and Quaternions and Vectors must be swizzled into their different elements) you want to put in the string and how many digits/characters you want them to be, then make a ‘map’ of your string. Truncate/expand variables into the correct length, then parse them into string format and concatenate them together in the order you defined in the map. When reading a data encoded this way, use the map again to create a reading function using Substring() to divide the string back into its different parts, then parse those parts back into the variable type needed. Essentially, the reverse of how you encoded it. Arrays and structs can be reassembled here also. Then you can output the variables for use in your game. There are probably other ways to do this also, but this is the way I have always done it. Note that when attempting to encode very long float variables(with lots of decimal places), that truncating them to the 3rd or 4th decimal place is usually fine, and 2nd place will even work for positions and rotations.