Ejemplo n.º 1
0
    IEnumerator SwapBall()
    {
        int     i  = 0;
        Vector3 p1 = selectedball.transform.position;
        Vector3 p2 = selectedball2.transform.position;
        var     c1 = Instantiate(selectedball);
        var     c2 = Instantiate(selectedball2);

        c1.GetComponent <SphereCollider>().enabled = false;
        c2.GetComponent <SphereCollider>().enabled = false;
        Destroy(c1.GetComponent <Rigidbody>());
        Destroy(c2.GetComponent <Rigidbody>());
        selectedball.GetComponent <Renderer>().enabled  = false;
        selectedball2.GetComponent <Renderer>().enabled = false;
        if (selectedball.childCount > 0)
        {
            selectedball.GetChild(0).GetComponent <Renderer>().enabled = false;
        }
        if (selectedball2.childCount > 0)
        {
            selectedball2.GetChild(0).GetComponent <Renderer>().enabled = false;
        }
        //

        for (float t = 0; t <= swap_time; t += Time.deltaTime)
        {
            i++;
            Vector3 m = (p1 - p2).normalized * Time.deltaTime / swap_time;
            c1.position -= m * 2;
            c2.position += m * 2;

            yield return(new WaitForSeconds(Time.deltaTime));
        }
        selectedball.position  = c1.position;
        selectedball2.position = c2.position;
        selectedball.GetComponent <Renderer>().enabled  = true;
        selectedball2.GetComponent <Renderer>().enabled = true;
        if (selectedball.childCount > 0)
        {
            selectedball.GetChild(0).GetComponent <Renderer>().enabled = true;
        }
        if (selectedball2.childCount > 0)
        {
            selectedball2.GetChild(0).GetComponent <Renderer>().enabled = true;
        }
        Destroy(c1.gameObject); Destroy(c2.gameObject);
        //text.GetComponent<TextMeshProUGUI>().text = CheckSameNear(selectedball).Count.ToString() + " " + CheckSameNear(selectedball2).Count.ToString();
        breakMatch(new List <Transform> {
            selectedball, selectedball2
        });
        selectedball = selectedball2 = null;
        onTurn       = false;
        Status_script.AddTurns(-1);
        yield return(new WaitForSeconds(Time.deltaTime));
    }