Multiple Spawn Points --- Check Point system

Going to place this up as I work on this and a couple more scripts today. I’m working on my spawn checkpoint system which allows you to go forward with the checkpoints but not backwards. Basically if I climb 250 feet (activate the spawn point), and fall down to 150, I can’t reactivate the spawnpoints at 150 and 200 feet.

The Lerpz spawn point that I grabbed isn’t working as intended, where it not only causes problems with my camera, but if I have more than one spawn point my game starts getting confused as to which spawn point to send me to (two spawn points, I “Activate” A clone, AKA #2, and it will SOMETIMES go to #2 and sometimes go to #1, no error was shown in the debug log during the initial testing of the points.

So what I’m checking for, is a system where when I hit checkpoint #1, I spawn at Checkpoint #1 when I die, if I hit #2, I cannot reactivate #1 and spawn at #2.

Respawn script from Lerpz tutorial, stripped of the particle effects:

/*
Respawn: Allows players to respawn to this point in the level, effectively saving their progress.

The Respawn object has three main states and one interim state: Inactive, Active and Respawn, plus Triggered.

- Inactive: Player hasn't reached this point and the player will not respawn here.

- Active: Player has touched this respawn point, so the player will respawn here.

- Respawn: Player is respawning at this respawn point.

Each state has its own visual effect(s).

Respawn objects also require a simple collider, so the player can activate them. The collider is set as a trigger.

*/

var initialRespawn : Respawn;	// set this to the initial respawn point for the level.

var RespawnState = 0;

// Sound effects:
var SFXPlayerRespawn: AudioClip;

var SFXVolume: float;	// volume for one-shot sounds.

// The currently active respawn point. Static, so all instances of this script will share this variable.
static var currentRespawn : Respawn;

function Start()
{	

	RespawnState = 0;
	currentRespawn = initialRespawn;
}

function OnTriggerEnter()
{
	if (currentRespawn != this)		// make sure we're not respawning or re-activating an already active pad!
	{
		// turn the old respawn point off		
		// Set the current respawn point to be us and make it visible.
		currentRespawn = this;
	}
}

What I’m looking at:

PSUEDOCODE

static var currentspawn : Checkpoint;
var thisCheckpointsPosition //If it's the first spawn point, second, third, it can be dependant on height
var Locked; //If it's locked it can no longer be activated.

function OnTriggerEnter()
{
if (locked == false)
    {
    //Make this the active spawn point
    currentspawn = this;
    //Lock it off from being reactivated
    locked = true;
    }
}

I actually don’t know how I should go at the code, because I could use the locking method, but then if I skipped a checkpoint I might accidentally activate a checkpoint I missed earlier and have to run farther than I need to (missed 200 ft checkpoint, Hit the 150ft and 250ft checkpoints, if I hit the 200ft checkpoint now, I’ll have to go 100 feet instead of 50 feet to the next checkpoint… for example’s sake)

AND DON’T DIRECT ME TO PLAYERPREFS…

I got that last time and it provided absolutely no help to my level screen problem. I’m not saving the game, I’m not switching screens, I’m just telling my game where to send the player after the player dies. And to also tell the spawn points not to work if I hit one farther than where the player currently is.

EDIT: After re-testing the first script from Lerpz, they now work correctly (must’ve been the Unity 3 update or something), BUT I still need the checkpoints to check if they’re a farther point than the last touched spawn point.

Add a value to each spawn point. The first one would be 1, second 2, etc. Then when you get near a spawn point it could check the value of the currently active spawn point, and if it’s greater than the one it’s near then ignore it, if it’s less then change the active spawn point to the new one.

I just figured it out before I checked the thread:

/*
Respawn: Allows players to respawn to this point in the level, effectively saving their progress.

The Respawn object has three main states and one interim state: Inactive, Active and Respawn, plus Triggered.

- Inactive: Player hasn't reached this point and the player will not respawn here.

- Active: Player has touched this respawn point, so the player will respawn here.

- Respawn: Player is respawning at this respawn point.

Each state has its own visual effect(s).

Respawn objects also require a simple collider, so the player can activate them. The collider is set as a trigger.

*/

var initialRespawn : Respawn;	// set this to the initial respawn point for the level.

var RespawnState = 0;

// Sound effects:
var SFXPlayerRespawn: AudioClip;

var SFXVolume: float;	// volume for one-shot sounds.

// The currently active respawn point. Static, so all instances of this script will share this variable.
static var currentRespawn : Respawn;

//Sequencial System
public var checkpointOrder = 1;
var myCheckpoint = 1;

function Start()
{	

	RespawnState = 0;
	currentRespawn = initialRespawn;
	checkpointOrder = 1;
}

function OnTriggerEnter()
{
if (myCheckpoint > checkpointOrder)
	{
	if (currentRespawn != this)		// make sure we're not respawning or re-activating an already active pad!
	{
		// turn the old respawn point off		
		// Set the current respawn point to be us and make it visible.
		checkpointOrder = myCheckpoint;
		currentRespawn = this;
		
	}
	}
}

Added two variables. The Public one can be changed by any of the spawn points, so that it can see the variable and change it if necessary. It prevents the currentRespawn to work if myCheckpoint is less than where I am in CheckpointOrder.

Yes I know public is dangerous but it’s either that or go through the tedious process of converting a variable to a static variable to just check if it’s greater than where I am in my checkpoint order.

TEST ONE: Hit Point two, does spawn it spawn to the correct spot? — Yes
TEST TWO: Hit point two, then point one, does it spawn to point two? — Yes
TEST THREE: If I hit spawn 1, then 2, then 3, does it go to spawn three? — Yes
TEST FOUR: If I hit any points before the last spawn point, do I go to the earlier spawn points? — No

Success!

Now onto my pause menu scripts! (One for death, another for pausing)