(-o^_^)-o Wishes that things could be just like they used to!
Uh oh! It looks like the HugMonster was a little too tight with its squeeze! That was fun, it really wants to do that again!
And now you can! Just press the space bar when you get a game over and you can restart your level.
I’ve automated as much as possible. The player and hugmonster don’t need any special babysitting for resetting their state to whatever it was initialized as. The switches are another story, and that’s because they have individualized behaviours for every level. I have the following idiom :
using UnityEngine;
using System.Collections;
public class ResetBehaviour : MonoBehaviour {
public Vector3 resetToPosition;
public Quaternion resetToRotation;
public Vector3 resetRigidBodyToVelocity;
public Vector3 resetAngularVelocity;
// Use this for initialization
void Start () {
RecordStartingVariables();
}
public void RecordStartingVariables(){
resetToPosition = transform.position;
resetToRotation = transform.rotation;
if(rigidbody != null){
resetRigidBodyToVelocity = rigidbody.velocity;
resetAngularVelocity = rigidbody.angularVelocity;
}
}
public void ResetGO(){
Debug.Log("Default ResetBehavoiur");
transform.position = resetToPosition;
transform.rotation = resetToRotation;
if(rigidbody){
rigidbody.velocity = resetRigidBodyToVelocity;
rigidbody.angularVelocity = resetAngularVelocity;
}
}
}
The player, hugmonster, and anything else that requires more than simply transform and velocity resets extends this class and declares new versions of Record / Reset. It works out really nicely for most things, but again, those switches… because they have individualized behaviors and each level has its own Switch handling delegate, it’s got to be repeated for every switch delegate. I guess that’s better than some alternatives.
But this is exciting! I’ve got all the basics up and running. Multiple levels, restarting on game over, enemy AI, user control, and environment interactions. There are still some more unique environment tricks I want to pull, but this is a really solid start and sets me up for a lot of level design. I guess I could use a title and end screen while I’m at it. 
