1.)I kind of cheated there and just tossed $10 at it on the asset store: S-Spell
That being said it still took my 3 days or so to integrate everything in well enough to where I was happy with it and still had all the functionality of before.
2.) Check points are actually a toggle system and two scripts interacting with the player object. I have a game control and a spawn point that does not destroy on load. I also have a default spawn point set in each scene. Here is the basic idea of the code. TODO: make it actually save out when you quit the game so you can resume from there, it just makes a checkpoint for the current game session/scene.
//need to know a respawn point, and if to use a default set in the level or one that doesn’t destroy and moves to a checkpoint object. You also need to know about the player to move them to the spawn point transform.
Game control code below:
public bool setToDefaultSpawnPoints=true;
public GameObject playerRespawnPoint;
public Player player;
//the line below allows any class to access this one without finding it and such. Just use Globalcontrol.Instance.
public static GlobalControl Instance;
private void Awake()
{
if (Instance == null) {
DontDestroyOnLoad (transform.root.gameObject);
Instance = this;
SceneManager.sceneLoaded += OnSceneLoaded;
} else {
Destroy (gameObject);
}
}
private void OnSceneLoaded (Scene scene, LoadSceneMode mode)
{
player = FindObjectOfType<Player> ();
//Find leveling stuff.
SetExpBarOnLoad ();
//probably better way than tags to do this....
if (!setToDefaultSpawnPoints) {
playerRespawnPoint = GameObject.FindGameObjectWithTag ("PlayerRespawn");
} else {
playerRespawnPoint = GameObject.FindGameObjectWithTag ("InitialSpawn");
}
if (playerRespawnPoint == null) {
playerRespawnPoint = GameObject.FindGameObjectWithTag ("InitialSpawn");
}
}
from there you also want another script to be on the checkpoints.
private Player player;
public GameObject playerRespawnPoint;
// Use this for initialization
void Start () {
player = FindObjectOfType<Player> ();
}
void OnTriggerEnter(Collider other){
if (other.gameObject.tag == "Player") {
GlobalControl.Instance.setToDefaultSpawnPoints = false;
playerRespawnPoint = GameObject.FindGameObjectWithTag ("PlayerRespawn");
player.playerRespawnPoint = playerRespawnPoint;
player.playerRespawnPoint.transform.position = this.transform.position;
player.SavePlayer ();
}
the player will also need to know a spawn point and basically retrieve the one you want to use from your gamecontrol object.
so like on start you have:
transform.position = GlobalControl.Instance.playerRespawnPoint.transform.position;