示例#1
0
        private IEnumerator StartNextPlant()
        {
            yield return(new WaitForSeconds(_timeToNextPlant));

            if ((enabled) && (_plantPool.AvailableObjectCount > 0))
            {
                PlayingFieldTile newPlantLocation = _playingFieldGrid.GetRandomClearPatch();

                if (newPlantLocation != null)
                {
                    _startingPlants -= 1;

                    GameObject nextPlant = _plantPool.GetFirstAvailable();
                    if (nextPlant != null)
                    {
                        nextPlant.GetComponent <PlantLifecycle>().TileLocation = newPlantLocation;
                        nextPlant.SetActive(true);
                    }

                    _timeToNextPlant = _startingPlants > 0 ? Random.Range(0.2f, 0.5f) : 45.0f;
                }

                StartCoroutine(StartNextPlant());
            }
        }
        private void OnEnable()
        {
            _destinationTile = _playingFieldGrid.GetRandomTile(true);
            if (_destinationTile == null)
            {
                gameObject.SetActive(false);
                return;
            }

            _scale         = 0.5f;
            _entryComplete = false;

            _destinationTile.ObstructedBy = TileBlockers.Bug;
            _transform.position           = _destinationTile.Position + (Vector3.up * 12.0f);
            _transform.localScale         = Vector3.one * _scale;

            _animator.enabled      = true;
            _rigidbody.constraints = _startingConstraints;
            _rigidbody.velocity    = new Vector3(0.0f, -1.0f, 0.0f);

            _soundEffect.volume = 0.0f;
        }