예제 #1
0
파일: SlugHeal.cs 프로젝트: gr98577/adryft
    // Update is called once per frame
    void Update()
    {
        if (coList.Count != 0)
        {
            parent.numAlliesNear = coList.Count;
            alliesNeedHeal       = false;
            foreach (GameObject x in coList)
            {
                damageController xdc = x.GetComponent <damageController>();
                if (xdc.getHealth() < xdc.getMaxHealth())
                {
                    alliesNeedHeal = true;
                }
            }

            if (alliesNeedHeal)
            {
                if (!parent.wait && !parent.isHealing)
                {
                    parent.wait = true;
                    StartCoroutine(parent.Heal());
                    //GetComponent<SpriteRenderer>().enabled = true;
                }
            }
            else
            {
                if (!parent.wait && parent.isHealing)
                {
                    parent.wait = true;
                    StartCoroutine(parent.Move());
                    //GetComponent<SpriteRenderer>().enabled = false;
                }
            }
        }
        else
        {
            parent.numAlliesNear = 0;
        }


        if (parent.isHealing)
        {
            secondCount += healFactor * Time.deltaTime;
            if (secondCount >= 1f)
            {
                secondCount -= 1f;
                foreach (GameObject x in coList)
                {
                    x.GetComponent <damageController>().giveHealth(1);
                }
            }
            if (!parent.wait)
            {
            }

            frameCount++;
            if (frameCount == 9)
            {
                var clone1 = Instantiate(gas1, transform.position, Quaternion.identity);
            }
            else if (frameCount >= 18)
            {
                frameCount = 0;
                var clone2 = Instantiate(gas2, transform.position, Quaternion.identity);
            }
        }
        else
        {
            moveLoc = new Vector3(0f, 0f, 0f);
            foreach (GameObject x in coList)
            {
                moveLoc += x.transform.position;
            }
            moveLoc /= coList.Count;

            if (coList.Count != 0)
            {
                parent.MoveTo(moveLoc);
            }
            else
            {
                parent.RunAway();
            }
        }
    }