IEnumerator Explosion()
    {
        TargetPlanet targetFly = null;

        foreach (var item in GetComponent <GamePlayManager>().targetPlanet)
        {
            if (planetConnected[0].GetComponent <SpriteRenderer>().sprite == item.ItemTarget.GetComponent <Image>().sprite&& item.Count < item.NumOfTarget)
            {
                targetFly = item;
                //set color
                var col = flyPaticle.GetComponent <ParticleSystem>().colorOverLifetime;
                col.enabled = true;
                Gradient grad = new Gradient();
                Color    c    = planetConnected[0].GetComponent <PlanetElement>().GetPlanetColor();
                grad.SetKeys(new GradientColorKey[] { new GradientColorKey(Color.white, 0.0f), new GradientColorKey(c, 0.3f), new GradientColorKey(c, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, 0.4f), new GradientAlphaKey(0.0f, 1.0f) });
                col.color = grad;
                if (item.Count + planetConnected.Count >= item.NumOfTarget)
                {
                    bool check = true;
                    foreach (var item2 in GetComponent <GamePlayManager>().targetPlanet)
                    {
                        if (item2 != item && item2.Count != item2.NumOfTarget)
                        {
                            check = false;
                            break;
                        }
                    }
                    if (check)
                    {
                        victory = true;
                    }
                }
                break;
            }
        }
        if (planetConnected.Count >= 5)
        {
            Debug.Log(planetConnected[0].transform.position);
            GameObject.FindGameObjectWithTag("PopupContainer").GetComponent <PopupManager>().showPopup("Great");
        }
        for (int i = 0; i < planetConnected.Count; i++)
        {
            planetConnected[i].GetComponent <PlanetElement>().Explosion();
            if (planetConnected.Count - i <= 6)
            {
                yield return(new WaitForSeconds(0.08f));
            }
            GetComponent <GamePlayManager>().addScore(10);
            if (targetFly != null && i < planetConnected.Count)
            {
                GameObject particle = Instantiate(flyPaticle, new Vector3(planetConnected[i].transform.position.x, planetConnected[i].transform.position.y, -1f), Quaternion.identity);
                float      timeFly  = 1.5f;
                particle.transform.DOMove(targetFly.ItemTarget.transform.position, timeFly).SetEase(Ease.InOutCubic);
                StartCoroutine(flyComplete(targetFly, timeFly));
                Destroy(particle, timeFly);
            }
        }
        planetConnected.Clear();
    }
Example #2
0
 public override void Update(double lastUpdateTime)
 {
     if (Math.Round(Path[Path.Count - 1].X) == Math.Round(Position.X) && Math.Round(Path[Path.Count - 1].Y) == Math.Round(Position.Y) && CompletionIndication == false)
     {
         TargetPlanet.SpaceShipArrival(this);
         CompletionIndication = true;
     }
 }
    IEnumerator flyComplete(TargetPlanet target, float time)
    {
        isFalling = true;
        yield return(new WaitForSeconds(time));

        if (target.Count < target.NumOfTarget)
        {
            target.Count++;
            if (target.Count == target.NumOfTarget)
            {
                target.ItemTarget.transform.GetChild(0).gameObject.SetActive(false);
                target.ItemTarget.transform.GetChild(1).gameObject.SetActive(true);
            }
            else
            {
                target.ItemTarget.GetComponentInChildren <Text>().text = target.Count.ToString() + "/" + target.NumOfTarget.ToString();
            }
            DOTween.Kill("scoreAdd");
            target.ItemTarget.transform.DOScale(1.3f, 0.05f).SetId("scoreAdd");
            target.ItemTarget.transform.DOScale(1f, 0.2f).SetId("scoreAdd").SetDelay(0.05f);
        }
        isFalling = false;
    }