Im trying to figure out how to destroy gameobject(ball) with other gameobject(ant) on mouseclick. I have 2 objects and both have Rigidbody 2d + Circe collider 2d. This script is attached to gameobject(ant)
this destroys object even im not clicking it on top of the ant gameobject so it destroys from everywhere i click.
using UnityEngine;
using System.Collections;
public class DestroyOnClicked : MonoBehaviour {
public GameObject ant;
void FixedUpdate ()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if(hit.collider != null)
{
if(hit.collider == gameObject.collider2D);
{
Destroy(gameObject);
}
}
}
}
}