예제 #1
0
    void Start()
    {
        RangedFlyingEnemy ranged   = gameObject.GetComponent <RangedFlyingEnemy>();
        MinibossScript    miniboss = gameObject.GetComponent <MinibossScript>();

        if (ranged != null || miniboss != null)
        {
            speed = Random.Range(1060f, 1120f);
        }
        else
        {
            speed = Random.Range(1145f, 1170f);
            distanceToStayAwayFromPlayer = 0f;
        }
        seeker = GetComponent <Seeker>();
        rb     = GetComponent <Rigidbody2D>();

        if (target == null)
        {
            if (!searchingForPlayer)
            {
                searchingForPlayer = true;
                StartCoroutine(SearchForPlayer());
                return;
            }
        }

        Vector3 playerPos = new Vector3(target.position.x, target.position.y + distanceToStayAwayFromPlayer, target.position.z);

        // Start a new path to the target position, return the result to the OnPathComplete method

        seeker.StartPath(transform.position, playerPos, OnPathComplete);

        StartCoroutine(UpdatePath());
    }
    IEnumerator DescentManager()
    {
        bool continueDescent = true;

        while (continueDescent)
        {
            foreach (Transform trans in objectsDescending)
            {
                if (trans.position.y < descentEnd)
                {
                    if (trans.name == "ForceField(Clone)")
                    {
                        foreach (Transform trans2 in objectsDescending)
                        {
                            SlowDescent sd = trans2.GetComponent <SlowDescent>();
                            Destroy(sd);
                            EnemyAI eai = trans2.GetComponent <EnemyAI>();
                            if (eai != null)
                            {
                                eai.nowDescending = false;
                                RangedFlyingEnemy rfe      = trans2.GetComponent <RangedFlyingEnemy>();
                                MinibossScript    miniboss = trans2.GetComponent <MinibossScript>();
                                if (rfe != null)
                                {
                                    rfe.nowDescending = false;
                                }
                                else if (miniboss != null)
                                {
                                    miniboss.nowDescending = false;
                                }
                            }
                        }
                        Destroy(trans.gameObject);
                    }
                    continueDescent = false;
                    break;
                }
            }
            yield return(new WaitForSeconds(0.2f));
        }
        Destroy(gameObject);
    }