I am attempting to make my camera lock position when a gameObject tagged “Enemy” is found, but after enemies are destroyed, to move along with player.
Code:
var target : Transform;
var distance : float;
var speed : float = 1;
var EnTarget : Transform;
var tracking : boolean = false;
function Update(){
if (!target){
target = GameObject.FindWithTag("Player").transform;
}
if(target.transform.position.z > Camera.main.transform.position.z+150){
transform.Translate(Vector3(speed,0,0));// = target.position.z+170 -distance;
}
if(!EnTarget){
EnTarget = GameObject.FindWithTag("Enemy").transform;
}
if(EnTarget != null){
tracking = true;
}else{
tracking = false;
}
if(tracking == true){
speed = 0;
}
if(tracking == false){
speed = 2;
}
}
It works perfectly as far as following the player, but when an enemy is found, it permanently locks, even after there are no enemies.