I want to turn the canvas to look at player camera but it only works for the first in hierarchy instance here is one of codes i tried to fix it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyHpBarLookAt : MonoBehaviour
{
void Update()
{
foreach(Transform enem in transform)
foreach(Transform child in enem)
{
if(child != null)
{
EnemyHpBar cameraPosFun = (EnemyHpBar) child.transform.GetComponent(typeof(EnemyHpBar)) as EnemyHpBar;
var pos = cameraPosFun.getPos();
child.transform.LookAt(pos);
Debug.Log(child.GetInstanceID());
}
}
}
}