示例#1
0
        /// <summary>
        /// Implements <see cref="CgfGames.IAsteroidView.SpawnAsteroid"/>
        /// </summary>
        public IAsteroidView SpawnAsteroid(Vector3 shipPos)
        {
            // Get random asteroid init pos far from the ship.
            Vector3 pos = SpaceObjectMngr.RandomPos();

            while (SpaceObjectMngr.SmartPath(pos, shipPos).sqrMagnitude <
                   2.5f * 2.5f)
            {
                pos = SpaceObjectMngr.RandomPos();
            }
            // Spawn and init ship.
            AsteroidView asteroidView = this.asteroidPool
                                        .Get(
                pos, Quaternion.Euler(0, 0, Random.value * 360)
                ).GetComponent <AsteroidView> ();

            asteroidView.Init(
                AsteroidCtrl.MAX_SIZE,
                this.asteroidPool,
                this.powerupPool,
                this.asteroidExplosionPool
                );
            return(asteroidView);
        }
示例#2
0
        /// <summary>
        /// Coroutine for the previous method.
        /// </summary>
        private IEnumerator Teleport2(Action teleportDone)
        {
            // Complex sequence for teleporting:
            // Step 1:
            this.teleportPs.Play();
            _audio.PlayOneShot(this.teleportClip);
            _col.enabled = false;
            yield return(new WaitForSeconds(0.25f));

            // Step 2:
            _rend.enabled = false;
            yield return(new WaitForSeconds(1.5f));

            // Step 3:
            _trans.position = SpaceObjectMngr.RandomPos();
            _rb.Sleep();
            teleportPs.Play();
            yield return(new WaitForSeconds(0.25f));

            // Step 4:
            this.SetActiveSoft(true);
            _audio.PlayOneShot(this.teleportClip);
            teleportDone.Invoke();
        }