I'm having trouble using the buttons on the runtime-generated in Unity 5. Buttons have been created correctly, but I have some problems in this audience. I use this code to make buttons that do:
foreach (string str in _scene.PDF_ITEMS) {button = (GameObject) Instantiate (_primitive); Button.GetConnector & lt; Button & gt; (). OnClick.AddListener ((= = Open PDF (str)); button. Gatecampant in Child & lt; Text & gt; (). Text = str; Button.GetConnector & lt; Transforms & gt; (). Setpaper (this. Transform, false); GetComponent & lt; RectTransform & gt; (). AnchorMin = Vector2.zero; GetComponent & lt; RectTransform & gt; (). AnchorMax = Vector2.one; Width ++; }
And it OpenPDF function:
name private void OpenPDF (string) {string comandType; If (_scene.isCurrent (ArrayUtility.IndexOf & lt; String & gt; (_ scene.PDF_ITEMS, name)) comandType = ControllerScene.IN_CLOSE_ITEM + ""; Else comandType = Kantrolrsisin. IN_OPEN_ITEM + ""; _inj.addComand (comandType, "+ + (ArrayUtility.IndexOf & lt; string & gt; (_ scene.PDF_ITEMS, name)));}
the problem is that when I played the scene; and a button Then I made the listener of the last button I created it (the function "Open" in the last "str" forward cycle in open pdf).
I think your problem is worse than this Bound to:
Try to work with a copy of the string
foreach (string str in _scene.PDF_ITEMS) {string strCopy = string.Copy (str); Button = (Game Object) institute (_primitive); Button.GetCompanyant & lt; Button & gt; (). OnClick.AddListener ((=) Open PDF (stroke); Button .GetCompNant in Child
No comments:
Post a Comment