示例#1
0
    private void FixedUpdate()
    {
        animator.SetBool("hit", true);
        this.particle.transform.position = this.transform.position;
        times += Time.fixedDeltaTime;

        // kinectPointController.ThreeWave();
        //机器人发球kinectPointController.Squats()
        if (playerStatus == PlayerStatus.robotServe)
        {
            if (Input.GetKey(KeyCode.W))
            {
                move = true;
            }
            if (kinectPointController.Squats())
            {
                move = true;
            }
        }
        if (move == true)
        {
            rightX = false;
            leftX  = false;
            speed  = TestTennisMove(startPosition, pointB.position);
            TennisMove(speed);
            hitTurn = 1; //机器人发球之后,轮到玩家击球。
        }
        if (playerStatus == PlayerStatus.serve)
        {
            //move = false;kinectPointController.HandUp()
            if (Input.GetKey(KeyCode.S))
            {
                hitTurn   = 0;
                hitMoving = true;
                fa        = true;
            }
            if (kinectPointController.HandUp())
            {
                hitTurn   = 0;
                hitMoving = true;
                fa        = true;
            }
        }
        if (hitMoving == true)
        {
            if (fa == true)
            {
                speed = TestTennisMove(playerServePos, pointB.position);
                TennisMove(speed);
            }
            if (leftX == true)
            {
                int i = 0;
                speed  = TestTennisMove(playerServePos, pointB.position);
                speed += new Vector3(-1.75f, 0, 0);
                TennisMove(speed);
                i++;
                if (i == 1)
                {
                    robotRandom = Random.Range(0, 10);
                    i           = 0;
                }
                hitTurn = 0;
                if (robotRandom >= 8)
                {
                }
            }
            if (rightX == true)
            {
                int i = 0;
                speed  = TestTennisMove(playerServePos, pointB.position);
                speed += new Vector3(3, 0, 0);
                TennisMove(speed);
                i++;
                if (i == 1)
                {
                    robotRandom = Random.Range(0, 10);
                    i           = 0;
                }
                hitTurn = 0;
                if (robotRandom >= 8)
                {
                }
            }
        }
        if (playerHit.canHit == true && hitTurn == 1)
        {
            Debug.Log(hitTurn);
            fa        = false;
            move      = false;
            hitMoving = true;
            if (Input.GetKey(KeyCode.A))  //左方向X轴
            {
                hitTurn = 0;
                leftX   = true;
            }
            if (kinectPointController.TwoWave())
            {
                hitTurn = 0;
                leftX   = true;
            }
            if (Input.GetKey(KeyCode.D))
            {
                hitTurn = 0;
                rightX  = true;
            }
            if (kinectPointController.ThreeWave())
            {
                hitTurn = 0;
                rightX  = true;
            }
        }
        //机器人回击
        if (kinecAction.robotHit && hitTurn == 0 && transform.position.z > pointB.position.z)
        {
            playerHit.canHit = false;
            if (robotRandom > 6)
            {
                animator.SetBool("hit", true);
                Quaternion a = new Quaternion(0, 180, 0, 0);
                pointA.transform.rotation = a;
                move    = false;
                hitTurn = 1;
            }
            else
            {
                animator.SetBool("hit", false);
                Quaternion a = new Quaternion(0, 180, 0, 0);
                pointA.transform.rotation = a;
                move      = true;
                hitMoving = false;
                hitTurn   = 1;
            }
        }
        //暂停
        if (kinectPointController.Stop() == true)
        {
            move      = false;
            hitMoving = false;
        }
        End();//得分
        #region 游戏结束
        if (int.Parse(robotGame.text) >= 7)
        {
            if (int.Parse(robotGame.text) - int.Parse(playerGame.text) >= 2)
            {
                game.SwitchSatus(Game.GameStatus.gameEnd1);
            }
        }
        if (int.Parse(playerGame.text) >= 7)
        {
            if (int.Parse(playerGame.text) - int.Parse(robotGame.text) >= 2)
            {
                game.SwitchSatus(Game.GameStatus.gameEnd2);
            }
        }
        #endregion
    }