#Help in Object Pooling
1 messages · Page 1 of 1 (latest)
theres no code for that. Im using a 2D Rectangle gameObject under Player named "CoinDetector" which has a collider
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?
Where is this code?
void Update()
{
if (pm.canAttract)
{
transform.position = Vector2.MoveTowards(transform.position, cs.playerTransform.position, cs.moveSpeed * Time.deltaTime);
}
}
I see no code about coins contacting things
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.tag == "CoinDetector")
{
cm.enabled = true;
}
}
if its collided, then coinMove script is enabled
Can you show more code?
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;
}```
It's hard to understand everything from these snippets
Sure