Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (tower != null)
        {
            if (currTarget != null)
            {
                if (Vector3.Distance(transform.position, currTarget.transform.position) <= tower.CurrentAttackRadius)
                {
                    if (timerShoot > 0)
                    {
                        timerShoot -= Time.deltaTime;
                    }
                    if (timerShoot < 0)
                    {
                        timerShoot = 0;
                    }

                    if (timerShoot == 0)
                    {
                        IMob mob = currTarget.GetComponent <BaseMob>(); // инициализируем интерфейс моба


                        CreateShoot(transform.position, currTarget.transform.position);

                        //

                        mob.ChangeHP(tower.CurrentDamage);     // отнимаем у него хп равное урону башни

                        timerShoot = tower.CurrentAttackSpeed; // возвращаем таймер скорости стрельбы башни в исходное положение
                    }
                }
                else
                {
                    currTarget = null;
                }
            }
            else
            {
                currTarget = FindTarget();
            }
        }
    }