Exemple #1
0
 IEnumerator FindNewTarget()
 {
     HitAbleInfo[] enemiesInRange = EntitySpawnManager.Instance.GetHitAbleInCircles(transform.position, HitAbleFindMask, MaxSightRange, true, true);
     for (int i = 0; i < enemiesInRange.Length; i++)
     {
         HitAble enemie = enemiesInRange[i].hitAble;
         if (enemie.ColliderIsOneOfYours(Physics2D.Raycast(transform.position, (enemie.MainCollider.bounds.center - transform.position), MaxSightRange, sightLayer).collider))
         {
             target = enemie;
             break;
         }
     }
     yield return(null);
 }
Exemple #2
0
    public void UpdateTarget()
    {
        if (target && !target.TargetTransform)
        {
            target = null;
        }

        FindNewTargetTimer += Time.deltaTime;
        UpdateTargetTimer  += Time.deltaTime;
        if (UpdateTargetTimer >= UpdateTargetTime)
        {
            if (target)
            {
                if (!target.ColliderIsOneOfYours(Physics2D.Raycast(transform.position, (target.ColliderCenter - transform.position), MaxSightRange, sightLayer).collider))
                {
                    //target out of sight;
                    target = null;
                }
            }
            if (!target)
            {
                if (FindNewTargetTimer >= FindNewTargetTime)
                {
                    StartCoroutine(FindNewTarget());
                    FindNewTargetTime = 0f;
                }
            }
            UpdateTargetTimer = 0f;
        }

        if (target)
        {
            targetPos = target.ColliderCenter;
            UpdateRotation();
        }
        else
        {
            UpdateRandomTimer += Time.deltaTime;
            if (UpdateRandomTimer >= UpdateRandomTime)
            {
                UpdateRandomTimer = 0f;
                FindRandomPos();
            }
        }
    }