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

public class CoinController : MonoBehaviour
{
    private Transform _player;
    private GameManager _gameManager;

    private void Start()
    {
        _player = GameObject.FindGameObjectWithTag("Player").transform;
    }
    private void FixedUpdate()
    {
        if(_gameManager == null)
        {
            _gameManager = GameManager.instance;
        }

        if(!_gameManager.magnet.isActive) { return; }

        if(Vector3.Distance(transform.position, _player.position) < _gameManager.magnet.GetRange())
        {
            var direction = (_player.position - transform.position).normalized;

            transform.position += direction * _gameManager.magnet.GetSpeed();
        }
    }
}
