Exemple #1
0
    private IEnumerator ReactSphere(GameObject bomb)
    {
        yield return(new WaitUntil(() => CreatingLevel.timer > 1.5f));

        musicSource.clip = sphereClip;
        musicSource.Play();
        RaycastHit[] hits = Physics.SphereCastAll(bomb.transform.position, 1.1f, new Vector3(0, -1f, 0), 10f);
        foreach (RaycastHit q in hits)
        {
            GameObject hitObject = q.transform.gameObject;
            CubeMove   target    = hitObject.GetComponent <CubeMove> ();
            if (target != null)
            {
                if ((int)target.kind == 2)
                {
                    spheres.Add(Instantiate(sphere, new Vector3(Mathf.Round(target.transform.position.x), target.transform.position.y + 1f, Mathf.Round(target.transform.position.z)), Quaternion.identity));
                    target.ReactToHit(true);
                }
                else if ((int)target.kind == 3)
                {
                    Ray        ray = new Ray(new Vector3(target.transform.position.x, 0.99f, target.transform.position.z), new Vector3(0, -1f, 0));
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit))
                    {
                        hitObject = hit.transform.gameObject;
                        PlatformLength platform = hitObject.GetComponent <PlatformLength> ();
                        if (platform != null)
                        {
                            platform.Decrease();
                        }
                    }
                    target.ReactToHit(false);
                }
                else
                {
                    target.ReactToHit(true);
                }
            }
        }
        spheres.RemoveAt(0);
        Destroy(bomb);
    }
Exemple #2
0
    private IEnumerator ReactPlane(GameObject plane)
    {
        yield return(new WaitUntil(() => CreatingLevel.timer > 1.5f));

        musicSource.clip = planeCrashClip;
        musicSource.Play();
        Ray        ray = new Ray(plane.transform.position, new Vector3(0, 1f, 0));
        RaycastHit hit;

        Destroy(plane);
        if (Physics.Raycast(ray, out hit))
        {
            GameObject hitObject = hit.transform.gameObject;
            CubeMove   target    = hitObject.GetComponent <CubeMove> ();
            if (target != null)
            {
                if ((int)target.kind == 2)                      //for green blocks
                {
                    spheres.Add(Instantiate(sphere, new Vector3(Mathf.Round(target.transform.position.x), target.transform.position.y + 1f, Mathf.Round(target.transform.position.z)), Quaternion.identity));
                    target.ReactToHit(true);
                }
                else if ((int)target.kind == 3)                      // for black blocks
                {
                    ray = new Ray(new Vector3(target.transform.position.x, 0.99f, target.transform.position.z), new Vector3(0, -1f, 0));
                    if (Physics.Raycast(ray, out hit))
                    {
                        hitObject = hit.transform.gameObject;
                        PlatformLength platform = hitObject.GetComponent <PlatformLength> ();
                        if (platform != null)
                        {
                            platform.Decrease();
                        }
                    }
                    target.ReactToHit(false);
                }
                else
                {
                    target.ReactToHit(true);
                }
            }
        }
    }