Get gameobject to follow new third person controller when original third person controller is destroyed.

Hi - in this script I have an object which moves towards the first person controller when that is active, and third person controller when this one is active.

Halfway through the game, the third person controller will be destroyed and a new one instantiated in its position - but I would like the object to then move towards this new third person controller.

I can’t give them both the same tag, so I’m not sure how to phrase the script - so that when the first person controller isn’t active and the original third person controller isn’t active it follows the new one?

Sorry - I haven’t got a script example of the ones I’ve tried as I haven’t got any that just don’t throw lots of errors.
If anyone could give me a pointer of where to look online or how to do it that would be amazing!

Thanks, Laurien

#pragma strict

var targetF : Transform;
var targetT : Transform;
var firstPerson : GameObject;


function Update () {

	if (firstPerson.GetComponent(CharacterController).active) {
	
	transform.position = Vector3.MoveTowards(transform.position,targetF.transform.position, 0.04f);
	
	transform.LookAt(targetF);
	
	}
	
	if (!firstPerson.GetComponent(CharacterController).active) {
	
	transform.position = Vector3.MoveTowards(transform.position,targetT.transform.position, 0.09f);
	
	transform.LookAt(targetT);

	
	}

}

If possible, it would be more efficient to move this code to the CharacterController, and do something like:

var objectScript : ObjectScript;

function Start() {
    objectScript = GameObject.Find('objectname').GetComponent(ObjectScript);
}

function Update() {
    if(active){
        objectScript.NewTarget(transform);
    }
}

And then have a NewTarget() function in the object’s script, like this:

function NewTarget(target:Transform) {
    transform.position = Vector3.MoveTowards(target.position...)
    transform.LookAt(target)
}

This has a couple of benefits. First, the object isn’t doing two GetComponent calls on every update (which can be slow), and secondly, when your second third person controller becomes active, the object will automatically start following it.

(pseudo code written without testing)

Edit - you’d also need a way to only fire the NewTarget() function when the CharacterController first becomes active, rather on every update!