How do i change On Click() parameter from script in c#
See image:
You can’t change the callbacks you have specified in the editor through a script. You have to do the whole job in the script.
public Button Button;
public UIController UIController;
private UnityEngine.Events.UnityAction buttonCallback;
private void AddAvatarCallback()
{
// Remove the last added callback
if( buttonCallback != null )
Button.onClick.RemoveListener( buttonCallback );
// Define new callback
if( /* some condition */ )
buttonCallback = () => UIController.OnClick_ShowAvatar( "My avatar #1" );
if( /* some other condition */ )
buttonCallback = () => UIController.OnClick_ShowAvatar( "My avatar #2" );
// Add callback to button
Button.onClick.AddListener( buttonCallback );
}