Exemple #1
0
    void SpawnAndAnimateBullet(Vector3 destination)
    {
        destination = animator.transform.InverseTransformPoint(destination);
        Vector3    startPoint = startTransform.localPosition;
        GameObject bulletObj  = animator.CreateObject(PrefabHolder.Instance.Bullet, startPoint);

        Bullet bullet = bulletObj.GetComponent <Bullet>();

        if (!bullet)
        {
            return;
        }

        bullet.Init(Gravity, startPoint, destination);
        bullet.SignalOnEndFlying.AddListener(OnBulletEndedFlying);
    }
    void Spawn(Enemy enemyToSpawn)
    {
        GameObject enemyPrefab = PrefabHolder.Instance.GetEnemy(enemyToSpawn.EnemyType());

        if (enemyPrefab)
        {
            float          t              = Random.Range(0f, 1f);
            Vector3        pointToSpawn   = Vector3.Lerp(leftBorder.position, rightBorder.position, t);
            GameObject     enemy          = animator.CreateObject(enemyPrefab, pointToSpawn, tower);
            WalkController walkController = enemy.GetComponent <WalkController>();
            if (!walkController)
            {
                return;
            }

            enemyToSpawn.EnemyDelegate += OnEnemyGotDamage;
            walkController.Init(tower.localPosition, enemyToSpawn.GetSpeed(), enemyToSpawn.enemyId);
            walkController.SignalOnEnemyDamagedTower.AddListener(OnEnemyWalkedToTower);
            enemies[enemyToSpawn.enemyId] = walkController;
        }
    }