using UnityEngine;
using System.Collections;
public class DüğünDurma : MonoBehaviour
{
public Animator[] animators;
public float rotationSpeed = 5f;
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
foreach (Animator anim in animators)
{
anim.speed = 0;
}
LookAtPlayer();
}
}
void LookAtPlayer()
{
Transform playerTransform = GameObject.FindWithTag("Player").transform;
foreach (Animator anim in animators)
{
StartCoroutine(RotateToFace(anim.transform, playerTransform));
}
}
IEnumerator RotateToFace(Transform character, Transform player)
{
while (Quaternion.Angle(character.rotation, player.rotation) > 0.1f)
{
character.rotation = Quaternion.Slerp(character.rotation, player.rotation, rotationSpeed * Time.deltaTime);
yield return null;
}
}
void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
foreach (Animator anim in animators)
{
anim.speed = 1;
}
}
}
}