I have a UI Button object in a 2D project. I’ve added a Rigidbody2D to it. It has a mass of 1, 0 for linear and angular drag, and zero for gravity scale. (see pic).
In code, in an OnClick event handler, I attempted to add a force to move the object.
btnItem =GameObject.FindGameObjectWithTag(“btnItem”);
rb = btnItem.GetComponent();
rb.AddForce(btnItem.transform.right *1000);
but the object does not move at all. If I give the rigid body a gravity scale of 1, it drops (as you might expect).
How should force be applied to move it? Please give a code example.