Hey all.
I’m creating a small drag-and-drop style item creation in my game. You click on the item in the menu, and the item follows the mouse until you click again, where it gets placed.
I make the object follow the mouse in the update function:
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z));
transform.position = new Vector3(mousePosition.x, mousePosition.y, -2.0f);
My problem is that I don’t want the object that has not been placed yet to affect other things on the screen. So I want to disable the box collider until it is placed. But when I do this, the object no longer follows the mouse around. It’s as if updating the position depends on the box collider, and I don’t understand why.
Here’s how I disable and enable the box collider:
DISABLE:
void Start()
{
this.gameObject.collider.active = false;
}
ENABLE"
void OnMouseOver()
{
if (Input.GetMouseButton(0) (!mouseDownFlag))
{
mouseDownFlag = true;
placed = true;
creator = GameObject.Find("Object Creator");
creator.GetComponent<CreateObjects>().ChangeRootColor(index);
this.gameObject.collider.active = true;
}
}
Any ideas on why an inactive collider would make the object not follow the mouse?