public void AddBall() { int ballSize = sceneContainer.GetBallPositions().Count; if (ballSize < 5) { var ballPre = Instantiate(ballPrefab); ballPre.transform.GetChild(0).GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; Vector3 ballPos = ballPre.transform.position; switch (ballSize) { case 1: ballPre.transform.position = new Vector3(ballPos.x + 2, ballPos.y, ballPos.z); break; case 2: ballPre.transform.position = new Vector3(ballPos.x - 2, ballPos.y, ballPos.z); break; case 3: ballPre.transform.position = new Vector3(ballPos.x, ballPos.y, ballPos.z + 2); break; case 4: ballPre.transform.position = new Vector3(ballPos.x, ballPos.y, ballPos.z - 2); break; } //SET BALLS RigidbodyContainer rigidbodyContainer = new RigidbodyContainer(); rigidbodyContainer.StoreRigidbody(ballPre.transform.GetChild(0).GetComponent <Rigidbody>()); sceneContainer.GetRigidbodyContainers().Add(rigidbodyContainer); sceneContainer.GetBalls().Add(ballPre.transform.GetChild(0).gameObject); sceneContainer.GetBallPositions().Add(ballPre.transform.GetChild(0).position); //SET SHADOWS sceneContainer.GetShadows().Add(ballPre.transform.GetChild(1).gameObject); sceneContainer.GetShadowPositions().Add(ballPre.transform.GetChild(1).position); } }