我以前做過這個沒有問題,但現在它不起作用。
我在 PlayFab 中實作 FriendsList 并使用預制按鈕填充 ScrollView 串列。我為每個按鈕添加了一個 OnClick 事件,但我無法觸發它。
我已經測驗了不同的方法,但仍然無法讓它作業。
我通過在螢屏底部和回圈之外添加一個按鈕進行了測驗,這很有效。我已經測驗將按鈕添加到串列中,然后在填充滾動視圖后添加 OnClick。
這是我目前使用的代碼:
void DisplayFriends(List<FriendInfo> friendsCache)
{
DestroyFriendsContainer();
foreach (FriendInfo _friends in friendsCache)
{
GameObject _listing = Instantiate(friendsPrefab, friendsContainer);
_listing.name = _friends.TitleDisplayName;
var _button = _listing.GetComponent<Button>();
_button.onClick.AddListener(SelectPlayerActivity);
print(">> " _button.name);
FriendsListing _tempListing = _listing.GetComponent<FriendsListing>();
Debug.Log(_tempListing.txt_PlayerName);
Debug.Log(_friends.TitleDisplayName);
_tempListing.txt_PlayerName.text = _friends.TitleDisplayName;
}
friendsCache.ForEach(f => Debug.Log(f.FriendPlayFabId));
}
void SelectPlayerActivity()
{
print("Player Name: ");
}
這是實際場景的圖片:

uj5u.com熱心網友回復:
您可以將其公開為 void 并在 gameObject 中制作 ButtonHandler 并使用該物件
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/448009.html
上一篇:設定旋轉軸為正值
下一篇:如何在編輯器中更改影片fps
