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:
On the Camera to focus on the enemy:
asked Mar 01 '11 at 10:37 PM
What I'd do is create an array holding reference to all enemy GameObjects. I guess a simple way would be to use:
then, in the script catching input, simply set myTarget to the enemy you clicked. Finally,have the camera focus on myTarget.
Plenty of better way, but that's the first I can think of :)
EDIT: Long story short, hold a single target reference rather than have plenty of on/off switch to parse through.
answered Mar 02 '11 at 12:24 AM