Beispiel #1
0
    public void UpdateTower(TowerManager towerManager)
    {
        m_ShootAccu += Time.deltaTime;
        if (m_CurrentTarget)
        {
            if (Vector3.Distance(transform.position, m_CurrentTarget.transform.position) > m_TowerRange)
            {
                ChangeTarget();
                return;
            }

            if (CanShoot())
            {
                m_ShootAccu = 0;
                Vector3 lookDir = (new Vector3(m_CurrentTarget.transform.position.x, 0, m_CurrentTarget.transform.position.z) - transform.position).normalized;
                transform.rotation = Quaternion.LookRotation(lookDir != Vector3.zero ? lookDir : Vector3.forward);

                if (m_BulletType == BulletType.Freezing)
                {
                    m_CurrentTarget.ApplySlow(0.5f, 2.0f);
                }
                else
                {
                    var bullet = towerManager.RequestBullet(m_BulletType);
                    bullet.Shoot(transform.position, m_CurrentTarget.transform.position, m_BulletDamageAmount, m_BulletSpeed, m_ExplodeRange);
                }
            }
        }
        else
        {
            GetTarget();
        }
    }