Beispiel #1
0
    //Recycle a ball without delay
    public virtual void RecycleBall(BallScript ball)
    {
        if (ball != null)
        {
            isRecycling = true;
            ball.EnableRigidbody();
            Vector3     instantiatePosition = transform.position;
            Rigidbody2D ballRigidbody       = ball.GetComponent <Rigidbody2D> ();
            ballRigidbody.velocity        = new Vector2(0, 0.5f);
            ballRigidbody.angularVelocity = 0.0f;

            instantiatePosition.y  += Random.Range(0.0f, 10.0f);
            instantiatePosition.x  += Random.Range(-2.0f, 2.0f);
            ball.transform.position = instantiatePosition;

            int   ballIndex    = -1;
            float randomNumber = Random.Range(0.0f, 1.0f);

            if (randomNumber < giantBallProbability)
            {
                ball.transform.localScale = new Vector3(2.0f, 2.0f, 2.0f);
            }
            else
            {
                ball.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
            }

            if (randomNumber < bombProbability)
            {
                ballIndex = BallScript.Constants.bombIndex;
                ball.Initiate(ballIndex, gameManager.bombSprite);
            }
            else
            {
                if (randomNumber < giantBallProbability + bombProbability)
                {
                    ball.gameObject.transform.localScale = new Vector3(2.0f, 2.0f, 2.0f);
                }
                ballIndex = Random.Range(0, gameManager.sprites.Length);
                if (!ballDictionary.ContainsKey(ballIndex))
                {
                    ballDictionary.Add(ballIndex, new List <BallScript> ());
                }
                ball.Initiate(ballIndex, gameManager.sprites[ballIndex]);
                ballDictionary [ballIndex].Add(ball);
            }
            ball.ForceIdle();
        }
        else
        {
            Debug.Log("Ball is null");
        }
    }