コード例 #1
0
    public void SpawnEnemy(BasicEnemy _enemy, Player player, Wave _wave)
    {
        if (startSpawn)
        {
            BasicEnemy enemy = Instantiate(_enemy);
            enemy.enemyStats.player = player;
            switch (enemy.enemyStats.type)
            {
            case (enemyType.small):
            case (enemyType.bonus):
                enemy.transform.position = getEasyEnemyPosition(player);
                break;

            case (enemyType.medium):
                enemy.transform.position = getMediumEnemyPosition(player);
                enemy.GetComponent <MediumEnemy>().spawnRate      = (0.5f * loopFactor * _wave.waveInfo.mediumFireRate);
                enemy.GetComponent <MediumEnemy>().enemyStats.hp *= (int)(loopFactor * _wave.waveInfo.HPFactor);
                break;

            case (enemyType.large):
                enemy.transform.position = getHardEnemyPosition(player);
                enemy.GetComponent <HardEnemy>().spawnRate      = (0.5f * loopFactor * _wave.waveInfo.LargeFireRate);
                enemy.GetComponent <HardEnemy>().enemyStats.hp *= (int)(loopFactor * _wave.waveInfo.HPFactor);
                break;

            default:
                enemy.transform.position = getHardEnemyPosition(player);
                break;
            }
        }

        //Debug.Log("Spawning Enemy: " + _enemy.name);
    }
コード例 #2
0
    void Start()
    {
        if (!m_Animator)
        {
            Debug.LogError("No Animator script has been assigned to " + gameObject.name);
        }
        if (!m_BasicEnemy)
        {
            Debug.LogError("No Basic Enemy script has been assigned to " + gameObject.name);
        }
        if (!m_EnemyPlayerDetection)
        {
            Debug.LogError("No Enemy Player Detection script has been assigned to " + gameObject.name);
        }
        if (!m_FloorCheckCollider)
        {
            Debug.LogError("No Floor Check Collider2D has been assigned to " + gameObject.name);
        }
        if (!m_WallCheckCollider)
        {
            Debug.LogError("No Wall Check Collider2D has been assigned to " + gameObject.name);
        }

        m_EnemyAudio = m_BasicEnemy.GetComponent <EnemyAudio>();
        m_Action     = Actions.EnemyPatrol;
    }
コード例 #3
0
        protected void SpawnProjectile(BasicEnemy enemy)
        {
            var player = FindPlayer(enemy.transform.position);

            var direction = Vector2.zero;

            if (player == null)
            {
                direction = rand.RandomDirection2D();
            }
            else
            {
                direction = player.transform.position - enemy.transform.position;
                direction = direction.normalized;
            }

            var spawned = Instantiate(projectiles[rand.RandomIntLessThan(projectiles.Length)]);

            spawned.transform.position = enemy.basicSpawnAnchor.transform.position;
            spawned.transform.parent   = GameManager.Instance.holder.transform;
            var proj = spawned.GetComponent <Projectile>();

            if (proj != null)
            {
                proj.SetVelocity(direction * speed);
                proj.doNotHitLayers = enemy.gameObject.layer;
                proj.doNotHit       = enemy.GetComponent <Resources>();
            }
        }
コード例 #4
0
    //攻击
    private void TryFire()
    {
        //当前时间超过下次攻击时间,开始搜索攻击目标
        //当变成范围塔时,m_RigidbodyEnemy失效
        if (isFireRange == false)
        {
            ResetMinEnemyHealth();
            //找到最小血量的敌人
            for (int i = 0; i < m_EnemyTriggerList.Count; i++)
            {
                m_BasicEnemyTemp = m_EnemyTriggerList[i].GetComponent <BasicEnemy>();
                //发现被要求集火的敌人
                if (m_BasicEnemyTemp.isFocused == true)
                {
                    m_BasicEnemyMinHealth = m_BasicEnemyTemp;
                    break;
                }
                if (minEnemyHealth > m_BasicEnemyTemp.GetHealth())
                {
                    minEnemyHealth        = m_BasicEnemyTemp.GetHealth();
                    m_BasicEnemyMinHealth = m_BasicEnemyTemp;
                }
            }
            //虽然逻辑上不可能进入这个函数后,发现没有敌人
            //但是还是保险起见
            if (m_BasicEnemyMinHealth != null)
            {
                //转向要攻击的目标
                m_RigidbodyEnemy = m_BasicEnemyMinHealth.GetComponent <Rigidbody>();
            }
        }

        //如果达到攻击间隔,开始攻击
        if (Time.time > nextFire)
        {
            //如果是范围塔,攻击每个进入范围的敌人
            if (isFireRange)
            {
                for (int i = 0; i < m_EnemyTriggerList.Count; i++)
                {
                    m_BasicEnemyTemp = m_EnemyTriggerList[i].GetComponent <BasicEnemy>();
                    Fire(m_BasicEnemyTemp);
                }
                m_RangeParticles.GetComponent <ParticleSystem>().Stop();
                m_RangeParticles.GetComponent <ParticleSystem>().Play();
                m_Animator.SetTrigger("Attack");
            }
            else
            {
                //虽然逻辑上不可能进入这个函数后,发现没有敌人
                //但是还是保险起见
                if (m_BasicEnemyMinHealth != null)
                {
                    Fire(m_BasicEnemyMinHealth);
                }
            }
            nextFire = Time.time + fireRateSpendSec;//计算下一次攻击时间
        }
    }
コード例 #5
0
    private void Start()
    {
        if (!m_BasicEnemy)
        {
            Debug.LogError("No Basic Enemy script attached to " + gameObject.name);
        }

        if (m_WaypointA.Equals(m_WaypointB))
        {
            Debug.LogWarning("Both waypoints for " + gameObject.name + " are equal.");
        }
        else if (m_WaypointB.x < m_WaypointA.x)
        {
            Debug.LogError("Invalid Waypoint positions. Waypoint B cannot be positioned before Waypoint A");
        }

        m_EnemyAudio = m_BasicEnemy.GetComponent <EnemyAudio>();
        m_Action     = Actions.EnemyMoveAction;
    }
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
//        battleSound.SetParameter("Player Health", (float)player.health/(float)player.maxHealth);
        if (!paused)
        {
            if (startTimer >= 0)
            {
                startTimer += Time.deltaTime;
            }
            startAnimTimer += Time.deltaTime;
            if (startAnimTimer >= startAnimTime && startAnimTimer >= 0)
            {
                for (int i = 0; i < startAnimations.Length; i++)
                {
                    startAnimations[i].enabled = true;
                }
                for (int i = 0; i < startAnimators.Length; i++)
                {
                    startAnimators[i].enabled = true;
                }
                enemy.GetComponent <SpriteRenderer>().sprite = CombatInfo.EnemySprite;

                enemy.SetName(CombatInfo.EnemyName);
            }
            if (startTimer >= startTime && startTimer >= 0)
            {
                if (CombatInfo.FightType == -1 && tuts[0] == 0)
                {
                    print("tut1");
                    tuts[0] = 1;
                    string[] text = { "press enter to advance", "hit the arrows using arrow keys", "before the timer runs out" };
                    TextBox.DisplayText(text, 4, true);
                    Pause(true);
                }
                else
                {
                    StartCombat();
                    startTimer = -1;
                }
            }
        }
    }
コード例 #7
0
    public override void onEnemySpawn(BasicEnemy enemy)
    {
        tk2dAnimatedSprite sprite = enemy.GetComponent <tk2dAnimatedSprite>();

        sprite.localTimeScale = Game.game.getEnemiesTimeScale();
    }