Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
846 B
1
Indexable
Never
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CoinMove : MonoBehaviour
{
    Coin cs;
    ObjectPooler op;
    PickupManager pm;

    private void Awake()
    {
        op = ObjectPooler.instance;
    }
    void Start()
    {
        cs = gameObject.GetComponent<Coin>();
        pm = FindObjectOfType<PickupManager>();

    }

  
    void Update()
    {
        if (pm.canAttract)
        {
            transform.position = Vector2.MoveTowards(transform.position, cs.playerTransform.position, cs.moveSpeed * Time.deltaTime);
        }
      


    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.gameObject.tag == "Player")
        {
            op.DeactivateGameObject(gameObject.tag, gameObject);
        }
    }

}
Leave a Comment