public class LookAtEnemyLogic : MonoBehaviour
{
private Transform enemy;
public float speed;
void Update()
{
if (enemy)
{
// Плавный поворот на врага
var targetRotation = Quaternion.LookRotation(enemy.transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);
}
}
private void OnTriggerStay(Collider player)
{
if (player.gameObject.CompareTag("Enemy") && !enemy)
{
enemy = player.transform;
}
}
private void OnTriggerExit(Collider other)
{
if(other.transform == enemy)
{
enemy = null;
}
}
}
public class LookAtEnemyLogic : MonoBehaviour
{
private Transform enemy;
public float speed;
void Update()
{
if (enemy)
{
// Плавный поворот на врага
var targetRotation = Quaternion.LookRotation(enemy.transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);
}
}
private void OnTriggerStay(Collider player)
{
if (player.gameObject.CompareTag("Enemy")&&!enemy)
{
enemy = player.transform;
}
}
}