void BallsRewindingUpdate() { if (Time.time > rewindStartTime) { clockTime -= Time.deltaTime; if (clockTime < 0) { clockTime = 0; } for (int i = 0; i < balls.Count; ++i) { PoolLoopBall ball = (PoolLoopBall)balls[i]; ball.UpdateScrubTime(clockTime); } if (clockTime == 0) { state = State.BEFORE_PREPARING_SHOT; for (int i = 0; i < balls.Count; ++i) { PoolLoopBall ball = (PoolLoopBall)balls[i]; ball.EnterActiveState(); } } } }
void EnterBallsActiveState() { state = State.BALLS_ACTIVE; MeshRenderer poolStickRenderer = poolStick.GetComponent <MeshRenderer>(); poolStickRenderer.enabled = false; Rigidbody2D body = cueBall.GetComponent <Rigidbody2D>(); Vector2 forceDirection = new Vector3(-Mathf.Cos(shotAngle), -Mathf.Sin(shotAngle), 0); Vector2 cueBallPos2d = new Vector2(cueBall.transform.position.x, cueBall.transform.position.y); Vector2 forcePosition = cueBallPos2d - forceDirection * cueBall.transform.localScale.x; body.AddForceAtPosition(forceDirection * Mathf.Pow(25, 1 + shotDistance), forcePosition); clockStart = Time.fixedTime; for (int i = 0; i < balls.Count; ++i) { PoolLoopBall ball = (PoolLoopBall)balls[i]; ball.EnterActiveState(); } }