Hey all,
I am trying to detect a mouse swipe using OverlapPoint on a 2d object that has a circle collider. I’ve spent a lot of time researching the new way to detect overlap points with 2d objects, and this code is working 80% of the time. In my start function for the spawned object I have:
c_collider2d = gameObject.GetComponent<Collider2D>();
My update function looks like this:
void Update() {
if (!paused)
{
if(Input.GetMouseButtonDown(0))
{
mouseIsDown = true;
}
if (mouseIsDown)
{
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mousePos = new Vector2(wp.x, wp.y);
if (c_collider2d == Physics2D.OverlapPoint(mousePos))
{
Debug.Log ("collision *****");
Destroy (this.gameObject);
}
}
if (Input.GetMouseButtonUp (0))
{
mouseIsDown = false;
}
transform.Rotate (Vector3.forward * rotationValue);
}
}
Obviously, I am missing something. 80% is great, but that isn’t going to cut it.
Does anyone see what I might be missing? (I’ve tried this with both Collider2D and CircleCollider2d and there is no difference in the ability to detect the overlap point.)
Any assistance is appreciated. Many thanks in advance.