Esempio n. 1
0
    IEnumerator CrystalCoroutine(int balNum)
    {
        Renderer r;
        int      prevHP;

        coll.enabled = false;

        yield return(new WaitForSeconds(2f));

        while (currHP > 0)
        {
            currentColor = (VisionType)Random.Range(1, 4);
            r            = cover.GetComponent <Renderer>();
            r.material.SetInt("_MaskType", 0);
            r.material.SetColor("_Color", Constants.Vision_Color(currentColor));
            r.material.SetInt("_StencilComp", 0);

            cover.transform.localScale = Vector3.zero;
            cover.SetActive(true);

            for (float timer = 0; timer <= 0.5f; timer += Time.deltaTime)
            {
                cover.transform.localScale = new Vector3(coverScale.x * timer / 0.5f, coverScale.y * timer / 0.5f, coverScale.z);
                yield return(null);
            }
            cover.transform.localScale = coverScale;
            balloons = new List <Balloon>();

            for (int i = 0; i < balNum; i++)
            {
                Balloon b    = new Balloon(spherePrefab, linePrefab, this);
                float   rad  = (Random.Range(0, 2) == 0 ? Random.Range(-90f, -20f) : Random.Range(20f, 90f)) * Mathf.PI / 180f;
                float   dist = Random.Range(6, 19);
                b.sphere.transform.position = new Vector3(Mathf.Sin(rad) * dist, Random.Range(5, 8), Mathf.Cos(rad) * dist);
                b.ChangeColor(currentColor);
                balloons.Add(b);
            }

            while (balloons.Count > 0)
            {
                yield return(null);
            }

            for (float timer = 0; timer <= 0.5f; timer += Time.deltaTime)
            {
                cover.transform.localScale = new Vector3(coverScale.x * (0.5f - timer) / 0.5f, coverScale.y * (0.5f - timer) / 0.5f, coverScale.z);
                yield return(null);
            }
            cover.SetActive(false);
            coll.enabled = true;
            prevHP       = currHP;

            for (float timer = 0; timer <= 9 - balNum * 2; timer += Time.deltaTime)
            {
                //if (prevHP - currHP >= maxHP / 2 + 1 || currHP <= 0) break;
                yield return(null);
            }
            coll.enabled = false;
        }
    }