Are ui button multiple on click() functions possible?

In my Game there is a “hold” button that makes the player “carry” an object which the camera is raycasting on: on the first click it lifts the object (and the player can move around with the object ‘carried’ in front of him), and on the next click it drops it. i made a script of two functions for both methods - and the button has a reference for both of them in the inspector’s ‘Button script’ “on click()” menu (which i’ve seen that it is able to add a bunch of functions and not just one).
perhaps i don’t fully understand the mean of this “on click()” menu, but the result is when i hit the button, it does both functions one by one (lifts the object and than drops it right away) in just one click.

here is my script:

public GameObject mainCamera;
	bool carrying;
	GameObject carriedObject;
	public float distance;
	public float smooth;

	void rotateObject() {
		carriedObject.transform.Rotate(5,10,15);
	}

	void carry(GameObject o) {
		o.transform.position = Vector3.Lerp (o.transform.position, mainCamera.transform.position + mainCamera.transform.forward * distance, Time.deltaTime * smooth);
		o.transform.rotation = Quaternion.identity;
	}

	public void pickup() {
			int x = Screen.width / 2;
			int y = Screen.height / 2;

			Ray ray = mainCamera.GetComponent<Camera>().ScreenPointToRay(new Vector3(x,y));
			RaycastHit hit;
			if(Physics.Raycast(ray, out hit)) {
			Pickupable p = hit.collider.transform.parent.GetComponent<Pickupable>();
				if(p != null) {
				Debug.Log ("ray has detected an object");
					carrying = true;
					carriedObject = p.gameObject;
					//p.gameObject.rigidbody.isKinematic = true;
					p.gameObject.GetComponent<Rigidbody>().useGravity = false;
				carry(carriedObject);
				}
			}

}



	public void dropObject() {
		if (carrying == true) {
			carrying = false;
			Debug.Log ("Dropped object");
			//carriedObject.gameObject.rigidbody.isKinematic = false;
			carriedObject.gameObject.GetComponent<Rigidbody> ().useGravity = true;
			carriedObject = null;
		}
	}
}

i should probably mention that this script was not originally written by me, i’ve made a few changes in it in order to make it compatible with touch input. originally the first line in the functions “pickup()” and “dropObject()” was “if(Input.GetKeyDown (KeyCode.E))” which determines if the key e was pressed (and i assume that the on click() method supposed to put it by). i tried to convert it to that button on click() method but it doesn’t seem to work seperatly. what would you suggest to do?

OnClick is an event. The way events work is that you can add listeners to them (In Unity’s case, you can do this in the inspector). You say that you added 2 listeners: pickup() and dropObject(), correct?

Every time an event occurs (The onclick event in case of a button) all the listeners of the event are invoked/called. So when you click, both methods will be called like you found out.

What you want is to not have 2 methods listening to that event which overwrite each other, but just one which does one of the 2 methods instead of both. Like so:

public void DoToggle()
{
    if (carrying)
    {
        dropObject();
    }
    else
    {
        pickup();
    }
}

And then add this method to the onclick in the inspector (and remove the other 2 listeners from that list)