예제 #1
0
    void HitBall()
    {
        if ((MatchManager.Instance.GetCurrentPlayer() == 1 && gameObject.tag == "Player") || (MatchManager.Instance.GetCurrentPlayer() == 2 && gameObject.tag == "Player2"))
        {
            ball.gameObject.GetComponent <Ball>().Freeze(false);
        }

        float   dist = Vector3.Distance(ball.transform.position, transform.position);
        Vector2 aim  = gp.rightStick.ReadValue();

        if (dist <= hitThreshold && hitCounter <= 0)
        {
            ball.transform.position = racket.transform.position;
            List <Vector3> ret = ballHitter.hitBall(aim, accuracy);
            ballRb.velocity = ret[1];
            if (gameObject.tag == "Player")
            {
                MatchManager.Instance.SetLastHit(1, ret[0]);
            }
            else if (gameObject.tag == "Player2")
            {
                MatchManager.Instance.SetLastHit(2, ret[0]);
            }
            audioClipHitBall.Play();
            hitCounter = hitCooldown;
        }
    }
예제 #2
0
    void HitBall()
    {
        ball.gameObject.GetComponent <Ball>().Freeze(false);
        float dist = Vector3.Distance(ball.transform.position, transform.position);

        if (dist <= hitThreshold)
        {
            ball.transform.position = racket.transform.position;
            BallHitter.Side side;
            float           sideR = UnityEngine.Random.value;
            if (sideR < 0.33)
            {
                side = BallHitter.Side.Left;
            }
            else if (sideR < 0.66)
            {
                side = BallHitter.Side.Center;
            }
            else
            {
                side = BallHitter.Side.Right;
            }

            BallHitter.Strength depth;
            float depthR = UnityEngine.Random.value;
            if (depthR < 0.15)
            {
                depth = BallHitter.Strength.Drop;
                Animator.SetTrigger("Strafe");
            }
            else if (depthR < 0.8)
            {
                depth = BallHitter.Strength.Middle;
                Animator.SetTrigger("Drive");
            }
            else
            {
                depth = BallHitter.Strength.Lob;
                Animator.SetTrigger("PowerfullShot");
            }


            Vector3 hit = ballHitter.hitBall(side, depth, difficulty)[1];
            ballRb.velocity = hit;
            MatchManager.Instance.SetLastHit(2, Vector3.zero);
            audioClipHitBall.Play();
        }
    }