public override void FixedUpdate()
        {
            Debug.Log(redBalls.GetComponentsInChildren <Transform>().Length);
            if (redBalls.GetComponentsInChildren <Transform>().Length == 1)
            {
                gameController.EndMatch();
            }
            else
            {
                var cueBallBody = cueBall.GetComponent <Rigidbody>();
                if (!(cueBallBody.IsSleeping() || cueBallBody.velocity == Vector3.zero))
                {
                    return;
                }

                foreach (var rigidbody in redBalls.GetComponentsInChildren <Rigidbody>())
                {
                    if (!(rigidbody.IsSleeping() || rigidbody.velocity == Vector3.zero))
                    {
                        return;
                    }
                }

                gameController.NextPlayer();
                // If all balls are sleeping, time for the next turn
                // This is kinda hacky but gets the job done
                gameController.currentState = new WaitingForStrikeState(gameController);
            }
        }
Exemplo n.º 2
0
        public override void FixedUpdate()
        {
            Debug.Log(redBalls.GetComponentsInChildren <Transform>().Length);
            if (redBalls.GetComponentsInChildren <Transform>().Length == 1)
            {
                gameController.EndMatch();
            }
            else
            {
                var cueBallBody = cueBall.GetComponent <Rigidbody>();
                cueBallBody.useGravity = true;
                //     CheckRangeOfCueBall(cueBallBody);
                //    var cueBallBodyret =  CheckIfToLetGravity(cueBallBody);
                ////////////// checking the gravity time


                if (flagTimer == 0)
                {
                    SetTimer();
                    flagTimer = 1;
                }
                if (time == 2)
                {
                    cueBallBody.useGravity = false;
                    cueBallBody.velocity   = Vector3.zero;

                    time      = 0;
                    flagTimer = 0;
                }

                //////////
                //  var dir = gameController.strikeDirection * -1;
                // var vec3 = Vector3(0, 0, -1);

                /*            if (cueBallBody.position.z < Z2 || cueBallBody.position.z > Z1 || cueBallBody.position.x < X2 || cueBallBody.position.x > X1)
                 *          {
                 *
                 *              cueBallBody.transform.position = new Vector3(0.01f, -4.98f, 4.77f);
                 *              cueBallBody.velocity = Vector3.zero;
                 *
                 *              mainCamera.transform.position = cueBall.transform.position - cameraOffset;
                 *              mainCamera.transform.rotation = cameraRotation;
                 *
                 *              cue.transform.position = cueBall.transform.position - cueOffset;
                 *              cue.transform.rotation = cueRotation;
                 *              cueBallBody.useGravity = false;
                 *
                 *          }
                 * */
                if (!(cueBallBody.IsSleeping() || cueBallBody.velocity == Vector3.zero))
                {
                    return;
                }

                /*   foreach (var rigidbody in redBalls.GetComponentsInChildren<Rigidbody>()) {
                 *      if (!(rigidbody.IsSleeping() || rigidbody.velocity == Vector3.zero))////// פה הבעיה !! הם ממשיכים לנוע לכן התור לא ממשיך !!
                 *          return;
                 *  }
                 *
                 *
                 */



                gameController.NextPlayer();
                // If all balls are sleeping, time for the next turn
                //
                gameController.currentState = new WaitingForStrikeState(gameController);
            }
        }