script button add Onclick Event()

Hi i look for Add OnClick Event() by script and set Object and fonction by script

first i found when i try use

button.onClick.SetPersistentListenerState

debug log say out of range

This question has been answered on Unity Answers.

TL;DR You can’t add persistent listeners at runtime, but you can add non-persistent listeners with button.onClick.AddListener().