Exemple #1
0
    void FindAndAttackEnemies()
    {
        Enemy closestEnemy = TownLocator.instance.GetClosestEnemy(transform.position);

        if (closestEnemy != null)
        {
            float distance = Vector3.Distance(closestEnemy.transform.position, transform.position);
            if (distance <= attackDistance)
            {
                transform.LookAt(closestEnemy.transform.position);

                attackTimer -= Time.deltaTime;
                if (attackTimer <= 0)
                {
                    attackTimer = 3.0f;

                    CannonBall newCannonBall = Instantiate(cannonBallPrefab) as CannonBall;
                    newCannonBall.Fire(launchPoint.transform.position, closestEnemy);
                }
            }
        }
    }