public void GenerationButton(string textButtton, int spectr) { OneButone _instantionSampleButton = Instantiate(_prefabButton, _gamePanel.transform); _instantionSampleButton.SetKey(textButtton); _instantionSampleButton.SetColor(_colorSpectr[spectr]); _instantionSampleButton.SetLife(_timeLife); bool refrash = true; float xButton = 0; float yButton = 0; int indexButton = 0; do { indexButton = Random.Range(0, _positionSectorButton.Count); if (_positionSectorButton[indexButton].z == 0) { refrash = false; xButton = _positionSectorButton[indexButton].x; yButton = _positionSectorButton[indexButton].y; _positionSectorButton[indexButton] = new Vector3(xButton, yButton, 1); } } while (refrash); xButton += Random.Range(-100, 100) / 100; yButton += Random.Range(-100, 100) / 100; _instantionSampleButton.transform.position = new Vector3(xButton, yButton, 11); _buttonsList.Add(_instantionSampleButton); StartCoroutine(RemovalFromTheList(_instantionSampleButton, _timeLife, indexButton)); }
IEnumerator RemovalFromTheList(OneButone _instantionSampleButton, float life, int indexPosition) { _instantionSampleButton.OnReturnResult += ddd; bool _state = false; void ddd(bool state) { _state = state; } yield return(new WaitForSeconds(life)); _positionSectorButton[indexPosition] = new Vector3(_positionSectorButton[indexPosition].x, _positionSectorButton[indexPosition].y, 0); OnReturnInfo(_state, _gamePanel.transform, _instantionSampleButton.gameObject.transform.position); _buttonsList.Remove(_instantionSampleButton); Destroy(_instantionSampleButton.gameObject); Destroy(_instantionSampleButton); }