Okay guys I am facing a hugely strange problem.
I create objects at runtime in my 2D scene and than add this component to them
public class DraggableItem : MonoBehaviour {
bool m_dragging;
public void Start()
{
m_dragging = false;
}
public void Update()
{
if (m_dragging)
{
transform.position=Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,-Camera.main.transform.position.z));
}
}
public void OnMouseDown()
{
m_dragging = true;
Debug.Log("MouseDown on " + gameObject.name);
}
public void OnMouseUp()
{
m_dragging = false;
}
}
Once I create a second of that object the first doesn’t respond anymore to clicks, but more strangely if I create e third object the second will continue responding as the third, the first still not catching any message. The behaviour is semi-random because it always appears in the same order, but with no reason.
I check my scene and still see the colliders enabled. If I disable/enable the collider2D components in inspector then it will have the desired behaviour, but removing all the other components won’t affect it. So I guess it’s a bug and can’t figure out how I can get rid of it.
Don’t hesitate to ask if anything seems blurry in my description.
Thanks.