1
\$\begingroup\$

So I want to be able to click on these targets and have them destroy themselves. Right now I have many OnMouse functions all just trying to print something for testing. For whatever reason it doesn't fire. I'm sure theres something simple I'm missing. Anyones help is greatly appreciated. Here is a picture of Unity itself and the code.

enter image description here

using UnityEngine;
using System.Collections;

public class TargetLogic : MonoBehaviour 
{

    // Use this for initialization
    void Start () 
    {

    }

    // Update is called once per frame
    void Update ()
    {
        //print("ok");
    }

    void OnMouseDown()
    {
        print("Works");
    }
    void OnMouseEnter()
    {
        print("Enter");
    }
    void OnMouseUp()
    {
        print("up");
    }
    void OnMouseOver()
    {
        print("Over");
    }
}

I also Have tried with a 2d Rigidbody as shown here

enter image description here

\$\endgroup\$
0
\$\begingroup\$

I see nothing wrong with your first setup, the only thing that may interfere could be another object over (in Z space) your target, with a collider attached to it.

The first collider in Z space is the one that get's the mouse events.

So try to disable everything except the MainCamera, the Light and your target, if it is working then there is something that overlaps your target, and this object is getting the mouse events.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ You were MOSTLY right. Right enough to lead me to what was wrong. So I took everything out besides a single target. Changed it Z sorting to 1 and BOOM! Works! Thanks so much! \$\endgroup\$ – Matt Griffin Apr 26 '14 at 2:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.