I am trying to develop a small 2D Unity platformer to learn to work with Unity's interface. I have been having an issue trying to make a gameobject track clones of an enemy and follow it. The function is to make it so when you hover on the enemy clone, it shows the enemy's health. But when I hover on the enemy, it tracks the position of the original enemy, not the clone. Both gameobjects have the same name. What I want is the GameObject HoverDataDisplay (as shown in the screenshot) to track its sibling, Enemy.
The current code that I have for the tracking script is as shown:
private GameObject Enemy;
void Start() {
Enemy = GameObject.Find ("Enemy");
}
void Update(){
transform.position = new Vector3 (Enemy.transform.position.x - 0.57f, Enemy.transform.position.y + 1.5f, Enemy.transform.position.z);
}
But the GameObject (HoverDataDisplay) Only follows the original enemy.
Thanks for your help!