Skip to main content
added 3 characters in body
Source Link
Lasse
  • 3.2k
  • 2
  • 22
  • 31

All UI follow functionality should be implemented in LateUpdate() method. See manual.

Example using your code:

void LateUpdate {
    Vector3 screenPoint = _camera.WorldToScreenPoint(transform.parent.position); // the parent is the enemy, I attached the script to the child canvas "HealthBar"
    _healthBarReact.position = screenPoint;
}

All follow functionality should be implemented in LateUpdate() method. See manual.

Example using your code:

void LateUpdate {
    Vector3 screenPoint = _camera.WorldToScreenPoint(transform.parent.position); // the parent is the enemy, I attached the script to the child canvas "HealthBar"
    _healthBarReact.position = screenPoint;
}

All UI follow functionality should be implemented in LateUpdate() method. See manual.

Example using your code:

void LateUpdate {
    Vector3 screenPoint = _camera.WorldToScreenPoint(transform.parent.position); // the parent is the enemy, I attached the script to the child canvas "HealthBar"
    _healthBarReact.position = screenPoint;
}
Source Link
Lasse
  • 3.2k
  • 2
  • 22
  • 31

All follow functionality should be implemented in LateUpdate() method. See manual.

Example using your code:

void LateUpdate {
    Vector3 screenPoint = _camera.WorldToScreenPoint(transform.parent.position); // the parent is the enemy, I attached the script to the child canvas "HealthBar"
    _healthBarReact.position = screenPoint;
}