using UnityEngine;

/// <summary>
/// GAME 1303 Tier 4 — A saw blade that spins. Cutthroat Course, Zap Attack.
///
/// SETUP
///  - Sprite of a blade + CircleCollider2D (Is Trigger ON, a bit smaller than the art)
///    + DamageOnContact (Damage 1 or Instant Kill) + this script.
///  - To make it travel, add Tier 1 MovingPlatform on the same object with waypoints
///    (it works fine on triggers — set Rider Tag to something unused so it doesn't
///    parent the player).
///  - Optional: an AudioSource with a looping saw sound; Pitch Follows Speed wobbles it.
///
/// Really just a rotator — reuse it for fans, gears, windmills.
/// </summary>
[RequireComponent(typeof(DamageOnContact))]
public class SpinningSaw : MonoBehaviour
{
    [Tooltip("Degrees per second. Negative = clockwise.")]
    public float spinSpeed = 360f;
    [Tooltip("Rotate the visual child instead of this object (so a collider stays put).")]
    public Transform visualToRotate;
    public AudioSource loopSound;
    public bool pitchFollowsSpeed = true;

    void Start()
    {
        if (loopSound != null) { loopSound.loop = true; if (!loopSound.isPlaying) loopSound.Play(); }
    }

    void Update()
    {
        Transform t = visualToRotate != null ? visualToRotate : transform;
        t.Rotate(0f, 0f, spinSpeed * Time.deltaTime);
        if (loopSound != null && pitchFollowsSpeed)
            loopSound.pitch = 0.8f + Mathf.Abs(spinSpeed) / 900f;
    }
}