I have a Player with a script. This script uses overlapSphere to look for Enemy Objects. The Problem is that it is not looking onto the nearest Enemy. What shoul I do ? Pls help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Attack : MonoBehaviour
{
[SerializeField] private float range;
public Transform EnemyG;
void Update()
{
Collider[] colliderArray = Physics.OverlapSphere(transform.position, range);
foreach(Collider collider in colliderArray)
{
if (collider.TryGetComponent<Enemy>(out Enemy enemy))
{
transform.LookAt(EnemyG);
}
}
}
}