I’m pretty new to this so any help would be much appreciated!
I’m trying to setup coins with pickup animations in my 2D platformer, my current code is:
public class CoinScript : MonoBehaviour
{
public GameObject coinPickup;
void OnCollisionEnter2D (Collision2D col)
{
if (col.gameObject.tag.Equals ("Player"))
{
Instantiate(coinPickup, transform.position, transform.rotation);
Destroy(gameObject);
}
}
It works fine when picking up the first coin ie the coin disappears and an animation is played (But only if it’s coin1 o.o) however when I then move to pickup a second coin it tells me the game object has already been destroyed and I end up kicking the coin away (they all have Rigidbody’s, I like em bouncy!)
The code seems to be removing the effect associated with the Instantiate line from other coins using the same script after it’s been ran once, is there an easy way to fix this?