コード例 #1
0
    void Start()
    {
        foundEnemyEvent.AddListener(FoundEnemy);

        target      = GameManager.instance.player.transform;
        agent       = GetComponent <NavMeshAgent>();
        thisFaction = GetComponent <FactionType>().faction;
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        thisFaction = GetComponent <FactionType>().faction;
        Collider[] colliders = Physics.OverlapSphere(transform.position, lookRadius);
        closestEnemy = Mathf.Infinity;

        foreach (Collider hit in colliders)
        {
            if (hit != null && hit.GetComponent <Enemy>() || hit.GetComponent <PlayerManager>())
            {
                FactionType tempFactionType = hit.transform.GetComponent <FactionType>();

                if (tempFactionType)
                {
                    //faction = tempFactionType.faction;
                    if (thisFaction != hit.GetComponent <FactionType>().faction)
                    {
                        float distToEnemy = Vector3.Distance(transform.position, hit.transform.position);
                        if (distToEnemy < closestEnemy)
                        {
                            closestEnemy = distToEnemy;
                            bestTarget   = hit.transform;
                        }

                        target = bestTarget;
                        //Debug.Log("bestTarget");
                    }
                }
            }
        }


        float distance = target ? Vector3.Distance(target.position, transform.position) : Mathf.Infinity;

        if (distance <= lookRadius)
        {
            foundEnemyEvent.Invoke();
        }
    }
コード例 #3
0
    public void SearchForFactions()
    {
        factionWaveManager = factionSpawn.GetComponent <FactionWaveManager>();
        enemies            = factionWaveManager.enemies;
        closestEnemy       = Mathf.Infinity;

        foreach (GameObject enemy in enemies)
        {
            Collider[] colliders = Physics.OverlapSphere(enemy.transform.position, searchRadius);

            foreach (Collider hit in colliders)
            {
                if (hit != null)
                {
                    FactionType tempFactionType = hit.transform.GetComponent <FactionType>();
                    if (tempFactionType)
                    {
                        faction = tempFactionType.faction;

                        if (faction != FactionType.Faction.None && faction != enemy.GetComponent <FactionType>().faction)
                        {
                            Enemy enemyHit    = hit.transform.GetComponent <Enemy>();
                            float distToEnemy = Vector3.Distance(hit.transform.position, enemy.transform.position);

                            if (enemyHit != null && distToEnemy < closestEnemy)
                            {
                                closestEnemy = distToEnemy;
                                bestTarget   = enemyHit.transform;
                            }

                            enemy.GetComponent <EnemyAI>().target = bestTarget;
                            // Debug.Log("TargetFound");
                        }
                    }
                }
            }
        }
    }
コード例 #4
0
 public void Initialise(List <GameObject> _enemies, FactionType.Faction _faction)
 {
     enemies = _enemies;
     faction = _faction;
 }
コード例 #5
0
 private void Start()
 {
     thisFaction = this.GetComponent <FactionType>().faction;
 }