/// <summary>
        /// Spawns and enables obstacle. Adds listener to spawn another object when this obstacle is disabled (when the obstacle leaves bounds).
        /// </summary>
        public void SpawnShape()
        {
            if (IsGameOver())
            {
                return;
            }

            GameObject obstacle;

            try
            {
                obstacle = _directionalSpawner.SpawnNew(obstaclePrefab.name);
            }
            catch (UnityException)
            {
                return;
            }

            obstacle.SetActive(true);

            RemoveListener();

            _actionWhenDisabled = obstacle.GetComponent <ActionOnDisabled> ();

            AddListener();
        }
示例#2
0
        private void Spawn()
        {
            var enemyObj = ObjectPool.instance.GetObjectForType(enemyPrefab.name, false);

            var renderer = enemyObj.GetComponentInChildren <SpriteRenderer> ();

            enemyObj.SetActive(true);

            Vector2 spawnLocation = PointWithinBounds.GetRandomWithoutBounds(
                renderer.sprite.bounds.size.x * renderer.gameObject.transform.localScale.x,
                renderer.sprite.bounds.size.y * renderer.gameObject.transform.localScale.y);


            enemyObj.transform.position = spawnLocation;

            RemoveListener();

            _enemyAction = enemyObj.GetComponent <ActionOnDisabled> ();

            AddListener();
        }
 private void AddEventOnPointCollected(GameObject pointObj)
 {
     RemoveListener();
     _pointsAction = pointObj.GetComponent <ActionOnDisabled> ();
     AddListener();
 }