using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemCoin : Item {
    public int value = 1;

    public GameSound pickupSound;

    Player playerBuf;

    [Header("Animation")]
    public Sprite [] coinSprites;
    public SpriteRenderer sr;
    public float animSpeed = 0.2f;

    float time = 0.0f;
    int frame = 0;

    public void Update() {

        time += Time.deltaTime;
        if(time > animSpeed) {
            time -= animSpeed;
            frame = (frame + 1) % coinSprites.Length;

            sr.sprite = coinSprites[frame];
        }
    }
    public void OnTriggerEnter(Collider col) {
        playerBuf = col.GetComponent<Player>();

        if(playerBuf != null) {
            playerBuf.AddCoins(value);
            pickupSound.Play();
            Destroy(gameObject);
        }
    }
}
