Esempio n. 1
0
    //Megtalálja a hozzá legközelebbi célpontot
    void UpdateTarget()
    {
        GameObject[] enemies = GameObject.FindGameObjectsWithTag(enemyTag);
        //Tárolja a legközelebbi ellenséget a közelben
        //Ha nem talál ellenséget
        float      shortestDistance = Mathf.Infinity;
        GameObject nearestEnemy     = null;

        foreach (GameObject enemy in enemies)
        {
            float distanceToEnemy = Vector3.Distance(transform.position, enemy.transform.position);
            //Ha találunk ellenséget akkor
            if (distanceToEnemy < shortestDistance)
            {
                shortestDistance = distanceToEnemy;
                nearestEnemy     = enemy;
            }
        }
        //Megtaláljuk a legközelebbi célpontot a taget lesz a legközelebbi célpont
        if (nearestEnemy != null && shortestDistance <= range)
        {
            target      = nearestEnemy.transform;
            targetEnemy = nearestEnemy.GetComponent <BasicEnemyScript>();
        }
        else
        {
            target = null;
        }
    }
Esempio n. 2
0
 void Start()
 {
     targetEnemy = GetComponent <BasicEnemyScript>();
     //target = GetComponent<Transform>();
     //ne ismételje meg minden egyes Update-ban ezt a metódust, elég kevesebbszer is (gépnek jót tesz)
     InvokeRepeating("UpdateTarget", 0f, 0.5f);
 }
Esempio n. 3
0
 public void InitializeSection()
 {
     for (int i = 0; i < ObjectSpawnPoints.Length; i++)
     {
         if (ObjectPool.Length >= 1)
         {
             if (Random.Range(0, 2) > 0)
             {
                 GameObject spawnedObject = ObjectPool[Random.Range(0, ObjectPool.Length)];
                 spawnedObject = GameObject.Instantiate <GameObject>(spawnedObject, ObjectSpawnPoints[i]);
                 //spawnedObject.transform.parent = null;
             }
         }
     }
     for (int i = 0; i < EnemySpawnPoints.Length; i++)
     {
         if (EnemyPool.Length >= 1)
         {
             if (Random.Range(0, 2) > 0)
             {
                 BasicEnemyScript spawnedEnemy = EnemyPool[Random.Range(0, EnemyPool.Length)];
                 spawnedEnemy = GameObject.Instantiate <BasicEnemyScript>(spawnedEnemy, EnemySpawnPoints[i]);
                 //spawnedEnemy.EnemyAI=(BasicEnemyScript.EnemyAiType)Random.Range(0,4);
                 spawnedEnemy.transform.parent = this.transform;
             }
         }
     }
 }
Esempio n. 4
0
    void OnTriggerStay2D(Collider2D other)
    {
        if (paused)
        {
            return;
        }
        if (colliderIsEnemy(other) && this.isDying == false)
        {
            BasicEnemyScript enemy = other.GetComponent <BasicEnemyScript> ();
            if (enemy == null || enemy.isDying)
            {
                return;
            }
            else
            {
                isTouchingEnemy(other);
            }

            if (attackTimer <= 0.0f)
            {
                attackTimer     = attackSpeed;
                attackAnimTimer = attackAnimSpeed;
                anim.SetInteger("State", MELEE);
                attackSound.Play();
                bool didKillEnemy = enemy.takeDamage(attackPower);
                if (didKillEnemy)
                {
                    stoppedTouchingEnemy(other);
                }
            }
        }
    }
Esempio n. 5
0
    // collisions

    void OnTriggerEnter2D(Collider2D other)
    {
        if (paused)
        {
            return;
        }
        if (colliderIsEnemy(other))
        {
            BasicEnemyScript enemy = other.GetComponent <BasicEnemyScript> ();
            if (enemy != null && enemy.isDying == false && this.isDying == false)
            {
                isTouchingEnemy(other);
            }
        }
    }
Esempio n. 6
0
 // Use this for initialization
 void Start()
 {
     enemyScript         = GetComponent <BasicEnemyScript>();
     scoreCanvas.enabled = true;
 }