using UnityEngine;

public class Spike : MonoBehaviour
{
    [SerializeField] Vector2 Velocity;

    Rigidbody2D rb;

    private void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }
    private void FixedUpdate()
    {
        rb.linearVelocity = Velocity;
        rb.rotation += 1f;
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        Velocity *= -1;
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        Player player = collision.gameObject.GetComponent<Player>();
        if (player != null)
        {
            player.ResetStuff();
            player.lifes = 3;
            player.UpdateLifeText();
            player.PlayHurtSound();
        }
    }
}
