Hello im trying to make a small game like you see in the video.
I want to destroy the player when enemy collided with it. (Player is square / Enemy is circle)
I tryed collision as you see in code but it didnt worked.
all of them has colliders (box and circle collider)
void Update()
{
transform.position = Vector2.MoveTowards(transform.position, moveposition.movepos[moveposIndex].position, speed * Time.deltaTime);
if (Vector2.Distance(transform.position, moveposition.movepos[moveposIndex].position) < 0.1f)
{
if (moveposIndex < moveposition.movepos.Length -1)
{
moveposIndex++;
}
else
{
Destroy(gameObject);
Debug.Log("Damage given");
}
}
if (Input.GetMouseButtonDown(0))
{
// Destroy(gameObject);
}
}
//private void OnCollisionEnter2D(Collision2D collision)
//{
// Destroy(collision.gameObject);
//}
}