I have a turret, which rotate to the player’s direction. I want to play audio during it’s rotation, but how can I do it in the script? I need to play it only when turret rotates.
Turret’s script:
public Camera mainCamera;
AudioSource audioTurretMove;
void Start()
{
audioTurretMove = gameObject.GetComponent<AudioSource>();
}
void Update()
{
var newRotation = Quaternion.LookRotation(
Camera.main.transform.position - transform.position).eulerAngles;
newRotation.x = 270;
newRotation.z = 0;
transform.rotation = Quaternion.Slerp(
transform.rotation,
Quaternion.Euler(newRotation),
Time.deltaTime);
}
