Using teleporters in a specific order to go somewhere new

Bear with me now… ^_^;;

I have two teleporters (teleportA, teleportB). If used individually, they will both send you to the same destination. However, if used in a specific sequence, I’d like to have them send you to a secondary destination.

So for example, if the player visited A, A, B, and then A, they would go to destination2. If used in any other sequence, it continues to return you to destination1.

I’m trying to figure out how to approach this. I’m thinking that having some sort of count variable is in order, but I’m not sure how to keep a record of the teleporters the player has used. I used a variable to create an extremely simplified version with just one teleporter and just visiting it a specific number of times, but obviously this doesn’t even come close to what I need to have happen. (Here’s the script just to prove I’m working at it!)

var destination1 : Transform; //where the player appears multiple times
var destination2 : Transform; //where the player ultimately goes
var target : GameObject; //the player
var teleportCount = 0; 
var teleportGoal = 5; //how many times the player has to enter the first teleporter
 
function OnTriggerEnter(other : Collider) {
    if (other.tag == "Player") {
    	if (teleportCount < teleportGoal) {
        	target.transform.position = destination1.position;
        	teleportCount ++;
        }
        else {
       		target.transform.position = destination2.position;
        }
    }  
    
}

If anyone has any ideas, I’d be greatly appreciative! I’m pretty good at following leads on the Unity scripting reference, but I don’t quite know how to distill what I need here into a search term… How might I get started on adding that second teleporter?

Thanks in advance!!

If you only have these two teleports and a single pattern, you could get away with a static List which contains identifiers for the teleports in the correct order. I’m thinking:

//This needs to be initialized somewhere. Easiest way is probly to hard-code it.
private static List< GameObject > sequence = new List< GameObject >();
private static int currentIndex = 0;

private Transform GetTargetLocation(){
    if(gameObject == sequence[currentIndex]){
        currentIndex++;
        if(currentIndex >= sequence.Count){
            currentIndex = 0;
            return destination2;
        }
    }else{
        currentIndex = 0;
    }
    return destination1;
}

If you have more teleports and multiple patterns, I would go for a singleton that keeps track of the player’s current teleport sequence and what all the possible patterns are. It also does the checking if the player’s current sequence matches a special sequence.

As for the sequences, I would create a class that describes one and store an array of these in the singleton. This way I can hard-code sequences, read them from a file or generate them randomly on the fly. Assuming all the sequences are of equal length, you could use a queue to keep track of the required amount of teleports. If the sequences differ in length, you’ll have to parse the lists appropriately. The class could look something like:

    public class TeleportSequence{
        private List<Teleport> sequence;
        private Transform destination;

        //the constructor for a hard coded sequence
        public TeleportSequence(int hardCodedIndex){/*initialize hard-coded values*/}

        /*You can have more constructors with different parameters if you want to
          read the sequences from file or generate them randomly*/

        /*send the destination by reference: if it's changed here, 
        the original changes too*/
        public bool CanTeleport(ref Transform teleportDestination, List<Teleport> currentSequence){
            //if sequence matches currentSequence
            {
                teleportDestination = new Transform(destination);
                return true;
            }
            return false;
        }
    }