#Help in Object Pooling

1 messages · Page 1 of 1 (latest)

inland zenith
#

Where is the range finding code?

serene flicker
#

so when a coin comes in contact, it moves towards player

#

but as u can see in video, after 10s when magnet has to be disabled, some coins farther away from coin detector are moving

#

I suspect this might be due to Object Pooling, as its detecting farther coin as the same coin which collided with it moments before

#

any solution?

inland zenith
serene flicker
#

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

}
inland zenith
#

I see no code about coins contacting things

serene flicker
#

private void OnTriggerEnter2D(Collider2D collision)
{

  if(collision.gameObject.tag == "CoinDetector")
    {
       
        cm.enabled = true;
    }  
}
#

if its collided, then coinMove script is enabled

inland zenith
#

Can you show more code?

serene flicker
#

Now this is another function which is called when a coin is to be moved

    {
        canAttract = true;
        CoinDetector.SetActive(true);
        yield return new WaitForSeconds(10f);
        CoinDetector.SetActive(false);
        canAttract = false;
    }```
inland zenith
#

It's hard to understand everything from these snippets

serene flicker
#

Can I give u links to the codes?

#

the full code

inland zenith
#

Sure

serene flicker
#

Activate Magnet is attached to Magnet prefab

#

PickupManager is attached to PickupManager GameObject