Using `FindWithTag ` is okay is used in Awake or Start. Just best to avoid in Update, methods called multiples times per frame or often. FindWithTag will return a `GameObject ` type but your list is a `CameraTarget ` type. You have to check if the player game object returned has a `CameraTarget ` component/script on it
public void Start()
{
// Find and return the player GameObject
GameObject player = GameObject.FindWithTag("Player");
// Assign a reference to the CameraTarget component on the player GameObject
// If a CameraTarget component does not exist on the player, this will be null
CameraTarget target = player.GetComponent();
// Check if the target has a value (not null)
// If so, add target to the CameraTarget list
if (target) CameraTargets.Add(target);
}
↧