コード例 #1
0
        private void BreakCluster(BalloonCluster cluster)
        {
            Stack <GameObject> clusterBalloons   = cluster.GetBalloons();
            GameObject         clusterGameObject = cluster.gameObject;

            foreach (GameObject balloon in clusterBalloons)
            {
                if (balloon == null)
                {
                    continue;
                }

                // Unparent the balloon
                balloon.transform.parent = null;

                // Enable the balloon's collider
                balloon.collider2D.enabled = true;

                // Enable wrapping
                balloon.SendMessage("EnableWrapping");

                // Give the balloon a velocity
                balloon.rigidbody2D.isKinematic = false;
                balloon.rigidbody2D.velocity    = clusterGameObject.rigidbody2D.velocity;

                Vector2 direction = Vector2.MoveTowards(balloon.transform.position, clusterGameObject.transform.position, -1f);
                balloon.rigidbody2D.AddForce(direction * 10f);
            }

            Destroy(clusterGameObject);
        }
コード例 #2
0
        public void DivideCluster(BalloonCluster cluster)
        {
            Stack <GameObject> clusterBalloons   = cluster.GetBalloons();
            GameObject         clusterGameObject = cluster.gameObject;
            int clusterSize = clusterBalloons.Count;

            // If the target cluster size is too small, just break up the cluster.
            if ((clusterSize / 2) < BalloonClusterController.MIN_BALLOONS_PER_CLUSTER)
            {
                this.BreakCluster(cluster);
                return;
            }

            // Take half the balloons in the cluster.
            int newClusterSize = clusterSize / 2;

            GameObject[] newClusterBalloons = new GameObject[newClusterSize];

            for (int i = 0; i < newClusterSize; i++)
            {
                newClusterBalloons[i] = clusterBalloons.Pop();
            }

            // Make a new cluster
            GameObject newCluster = this.MakeClusterWithBalloons(newClusterBalloons);

            newCluster.transform.position = clusterGameObject.transform.position + new Vector3(0.1f, 0.1f, 0);
            CircleCollider2D collider = newCluster.GetComponent <CircleCollider2D>();

            collider.radius = collider.radius / 2;
        }