Hi I have a coin and a player. I want the coin to move towards the player when the player get’s close enough and then destroy the coin.
Player has a rigidbody2D and a 2Dcollider
The coin has a rigidbody2D but 2x 2Dcolliders - one big circle collider to check if the player is close enough then the coin moves towards the player and the second one to trigger when the coin collides with the player so it can pick it up/destroy it. I’m not sure if this approach is the correct one, but it’s all I could think about.
Current state I’m in: player moves towards coin triggers big collider → coin moves towards player and nothing. I’m unsure on how to differentiate between 2 colliders on 1 gameobject so I can’t make the coin disappear when it hits the small collider. This is in 2D C#
public GameObject Collectibles;
public Transform Player;
private bool Triggered = false;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Player") Triggered = true;
}
void Update()
{
if (Triggered == true)
Collectibles.transform.position = Vector2.MoveTowards(transform.position, Player.transform.position, Time.deltaTime);
}