I'm making a hack n slash. The lock on system I'm currently using will focus the camera on both the character it follows and the enemy click by the mouse. The problem here is that because the camera searches by tag, it will only lock on to the closest enemy. Okay so the way I've fixed this is by making different tags entitled enemy1, enemy2, enemy3, etc. and scripts saying if they've been clicked or not. Is there at all an easier way to do this by just having 1 "enemy" tag? I basically want it so that whichever enemy I click, the camera will follow. The current way Im doing this is very tedious because of the repetition of nearly the exact same scripts.
I won't post the entire codes because they're really long, but I'll give a somewhat basic representation.
3 Enemies in the scene, respectively tagged 1,2, and 3.
On tag Enemy1:
static var HasBeenClicked:boolean = false;
function OnMouseDown()
{
Enemy1.HasBeenClicked = true;
Enemy2.HasBeenClicked = false;
Enemy3.HasBeenClicked = false;
}
On the Camera to focus on the enemy:
var damp = 20;
static var Ready:boolean = true;
var rotate;
function Update ()
{
if(Enemy1.HasBeenClicked == true)
{
rotate = Quaternion.LookRotation(GameObject.FindWithTag("enemy1").transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
}
if(Enemy2.HasBeenClicked == true)
{
rotate = Quaternion.LookRotation(GameObject.FindWithTag("enemy2").transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
}
if(Enemy3.HasBeenClicked == true)
{
rotate = Quaternion.LookRotation(GameObject.FindWithTag("enemy3").transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
}
}