Exemplo n.º 1
0
    public void Update()
    {
        float step = convergenceSpeed * Time.deltaTime;

        if (passed)
        {
            hueChange++;
            if (hueChange == 4)
            {
                hueChange = 0;
            }
            //GameObject plane = transform.GetChild(transform.childCount - 1).gameObject;
            Destroy(plane);
            gameObject.transform.DetachChildren();

            GameObject[] floats = GameObject.FindGameObjectsWithTag("float");
            foreach (GameObject g in floats)
            {
                Rigidbody rb = g.GetComponent <Rigidbody>();
                try
                {
                    rb.constraints = RigidbodyConstraints.None;
                    rb.isKinematic = false;
                }
                catch
                {
                }
                try
                {
                    rb.gameObject.GetComponent <SphereCollider>().radius = .4f;
                }
                catch
                {
                }
                Vector3 direction = transform.position - rb.gameObject.transform.position;
                rb.AddForce(direction.normalized * 20, ForceMode.Impulse);
                Invoke("Explode", 1f);
            }
            if (changeScore)
            {
                scoreScript.AddToScore();
                changeScore = false;
            }

            foreach (GameObject g in floats)
            {
                Destroy(g, 3f);
            }
        }

        if (failed)
        {
            Destroy(this.gameObject);
            GameObject[] floats = GameObject.FindGameObjectsWithTag("float");
            foreach (GameObject g in floats)
            {
                Rigidbody rb = g.GetComponent <Rigidbody>();
                rb.constraints = RigidbodyConstraints.None;
                rb.AddExplosionForce(10.0f, managerScript.convergenceSpot.transform.position, 10.0f);
            }
            foreach (GameObject g in floats)
            {
                Destroy(g);
            }
            managerScript.redExplosion.Play();
            Cam.GetComponent <AudioSource>().PlayOneShot(badExplode, 2f);
            Destroy(this.gameObject);
            // lose a life
            livesScript.LoseLife();
        }
    }