Here’s my problem… I’m trying to have coins move to a specific position in the top left when a ball passes through them. I tried setting the conditional using an if statement. However, because my code is in an ‘OnTriggerEnter2D’ method the coins only move when the collider of the ball is touching the colliders of the coins. I don’t know what to do. Please help.
Here’s my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class moveTowards : MonoBehaviour {
public Vector2 aPosition1 = new Vector2(-7, 4);
void OnTriggerEnter2D (Collider2D other)
{
if (other.tag == "Ball")
{
transform.position = Vector2.MoveTowards(new Vector2(transform.position.x, transform.position.y), aPosition1, 9 * Time.deltaTime);
Debug.Log("DID WE BUMP?");
}
}
}