using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class PlayersScrollPanelScript : MonoBehaviour { public GameObject PlayerSettingPrefab; private int playerCount = 0; // Start is called before the first frame update void Start() { updateScrollViewCount(4); } // Update is called once per frame void Update() { } public void updateScrollViewCount(float value) { playerCount = GetComponentsInChildren().Length; if (playerCount < value) { for (int i = playerCount; i < value; i++) { GameObject go = Instantiate(PlayerSettingPrefab, new Vector2(0, 0), Quaternion.identity) as GameObject; PlayerSetting ps = go.GetComponent(); ps.SetPlayerText(i + 1); ps.SetPlayerName(i + 1); ps.transform.SetParent(GameObject.Find("NewLocalGamePlayersContent").transform, false); ps.transform.SetSiblingIndex(i + 1); } } else if (playerCount > value) { for (int i = playerCount; i > value; i--) { PlayerSetting toDestroy = GameObject.Find("NewLocalGamePlayersContent").transform.GetChild(i - 1).GetComponent(); Destroy(toDestroy.gameObject); } } gameObject.GetComponent().verticalNormalizedPosition = 0f; playerCount = GetComponentsInChildren().Length; } }