Пример #1
0
 // Start is called before the first frame update
 void Start()
 {
     if (Prefab == null)
     {
         return;
     }
     Pool = new ObjectPool <Scout>(PoolSize, index =>
     {
         var prefab  = Instantiate(Prefab, transform);
         prefab.name = $"{name}-{nameof(Scout)}-{index+1}";
         prefab.SetActive(false);
         return(prefab.GetComponent <Scout>());
     });
     Pool.Activate();
 }
        /**
         * Spawns the projectile on given position and rotation.
         * Has also an angle.
         * @param: position, the position to spawn the prejctile.
         * @param: rotation, the roation on the spawned projectile.
         * @return: the spawned projectile.
         */
        public GameObject Spawn(Transform position, Quaternion rotation, ObjectPool pool)           // pool
        {
            rotation *= Quaternion.Euler(0, 0, Angle);

            var relPos = position.TransformPoint(Position);

            var bullet = pool.Activate(relPos, rotation);              // pool

            if (bullet == null)
            {
                return(null);
            }

            var bc = bullet.GetComponent <BulletController>();            // cannot be used 'as' ??

            bc.Speed     = Speed;
            bc.Damage    = Damage;
            bc.HitPrefab = HitPrefab;

            return(bullet.gameObject);
        }