Exemple #1
0
    private void LazerShoot(IGetDamage target)
    {
        IBullet bullet = new LazerBullet(lazerBulletType, currentLazerCanonStats.damage);

        target.GetDamage(bullet);
        lazerClip--;
    }
Exemple #2
0
    private void Shoot(IGetDamage target)
    {
        IBullet bullet = new MachineGunBullet(bulletType, currentMachineGunStats.damage);

        target.GetDamage(bullet);
        machineGunClip--;
    }
Exemple #3
0
    public void Fire(IGetDamage target)
    {
        if (heals < 0)
        {
            return;
        }
        if (_timeToNextMachineGunShoot < 0.01f)
        {
            Shoot(target);
            if (machineGunClip < 1)
            {
                _timeToNextMachineGunShoot = currentMachineGunStats.reloadDelay;
                StartCoroutine(ShootDelay(_timeToNextMachineGunShoot, () => machineGunClip = currentMachineGunStats.ammo));
            }
            _timeToNextMachineGunShoot = currentMachineGunStats.shootDelay;
            StartCoroutine(ShootDelay(_timeToNextMachineGunShoot));
        }

        if (_timeToNextLazerShoot < 0.01f)
        {
            LazerShoot(target);
            if (lazerClip < 1)
            {
                _timeToNextLazerShoot = currentLazerCanonStats.reloadDelay;
                StartCoroutine(ShootDelay(_timeToNextLazerShoot, () => lazerClip = currentLazerCanonStats.ammo));
            }
            _timeToNextLazerShoot = currentLazerCanonStats.shootDelay;
        }
        StartCoroutine(ShootDelay(_timeToNextLazerShoot));
    }
Exemple #4
0
 public virtual void UnderAttack(IAttack enemy)
 {
     if (target == null)
     //if (inAttackRadius(enemy.transform.position))
     {
         target = enemy.parent.HealthController;
         if (parent.Type == Unit.UnitType.Zombie)
         {
             parent.MoveController.Target = enemy.transform;
         }
     }
 }
Exemple #5
0
    public virtual void Attack()
    {
        if (target != null && target.isLive && inAttackRadius(target.transform.position))
        {
            isAttack = true;
            if (!isCoroutineStart)
            {
                StartCoroutine(DoAttack());
            }
            return;
        }
        target = null;
        Enemys.Clear();
        switch (myType)
        {
        case Unit.UnitType.Soldier:
        {
            Enemys.AddRange(MarkersManager.inst.enemys);
            break;
        }

        case Unit.UnitType.Zombie:
        {
            Enemys.AddRange(MarkersManager.inst.units);
            Enemys.Add(MarkersManager.inst.mainBase.transform.GetComponent <Unit>());
            break;
        }
        }
        if (Enemys.Count > 0)
        {
            var minDistance = (float)AttackRadius;
            foreach (var e in Enemys)
            {
                var dist = Vector3.Distance(e.transform.position, transform.position);
                if (dist < minDistance)
                {
                    minDistance = dist;
                    target      = e.HealthController;
                }
            }
        }
        if (target != null)
        {
            isAttack = true;
            StartCoroutine(DoAttack());
        }
        else
        {
            isAttack = false;
        }
    }
Exemple #6
0
 private void Start()
 {
     if (anim == null)
     {
         anim = transform.GetComponentInChildren <Animator>();
     }
     if (MoveController == null)
     {
         MoveController = GetComponent <IMove>();
     }
     if (MoveController == null)
     {
         MoveController = transform.GetComponentInChildren <IMove>();
     }
     if (MoveController != null)
     {
         MoveController.SetParent(this);
     }
     if (AttackController == null)
     {
         AttackController = transform.GetComponentInChildren <IAttack>();
     }
     if (AttackController != null)
     {
         AttackController.SetParent(this);
     }
     if (HealthController == null)
     {
         HealthController = transform.GetComponentInChildren <IGetDamage>();
     }
     if (HealthController != null)
     {
         HealthController.SetParent(this);
     }
     if (MoveController != null)
     {
         MoveController.Target = Target;
     }
     if (HPBar == null)
     {
         HPBar = transform.GetComponentInChildren <Image>();
     }
 }