コード例 #1
0
    private void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.tag == "Ball")
        {
            //other.rigidbody.AddExplosionForce(bumperForce, transform.position, 2, 0, ForceMode.Impulse);
            //other.rigidbody.AddForce(other.contacts[0].normal * bumperForce, ForceMode.Impulse);

            Vector3 dir = other.rigidbody.velocity.normalized;
            float   mag = other.rigidbody.velocity.magnitude;

            dir  = Vector3.Reflect(dir, other.contacts[0].normal);
            mag += bumperForce;

            other.rigidbody.velocity = dir * mag;

            //award points to the player who shot the ball
            BallAttach     ballScript    = other.transform.GetChild(0).GetComponent <BallAttach>();
            GameObject     playerAwarded = ballScript.lastHost;    //find the ball's last host
            PlayerMovement playerScript  = playerAwarded.GetComponent <PlayerMovement>();
            int            playerNum     = playerScript.playerNum; //access the host's number

            manager.IncreaseCombo(1);
            int points = DetermineScore();
            manager.AwardPointsToPlayer(points, playerNum); //award points to player for each bumper hit

            DoEffects();
        }
    }
コード例 #2
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Ball"))
     {
         BallAttach ballScript = other.transform.GetComponent <BallAttach>();
         CheckBallIntercept(ballScript.host);
     }
 }
コード例 #3
0
    public void ResetBallPos() //move ball to reset point
    {
        rb.velocity    = Vector3.zero;
        rb.constraints = RigidbodyConstraints.FreezePositionY;

        BallAttach ballScript = transform.GetChild(0).GetComponent <BallAttach>();

        if (ballScript.lastHost != null)
        {
            ballScript.ResetHost();
        }

        transform.position = resetPoint.position;
    }
コード例 #4
0
    protected void ShootBall()
    {
        BallAttach ballScript = ballCarried.GetComponent <BallAttach>();

        if (ballScript != null)
        {
            ballScript.HitBallWithForce(transform.forward, kickForce);
            audioManagerScript.PlaySound("ShootBall");
        }
        else
        {
            Debug.Log("Error: Ball cannot be released because its BallAttach script was not found.");
        }
        ReleaseBall();
    }
コード例 #5
0
    private void CheckBallIntercept(GameObject otherPlayer)
    {
        if (stolen)
        {
            return;         //prevents multiple steals from occuring in one collision
        }
        if (otherPlayer == this.gameObject)
        {
            return; //Prevents a glitch where a player intercepts the ball from himself
        }

        if (otherPlayer == null)
        {
            return; //in the case of collision with ball, does not activate interception if the ball doesn't have a host
        }

        PlayerMovement otherScript = otherPlayer.GetComponent <PlayerMovement>();

        if (otherScript == null)
        {
            return;
        }

        //in this case, we are sure its the other player

        if (otherScript.ballCarried == null) //does not intercept if the other player is not carrying a ball
        {
            return;
        }

        //they have the ball
        //Debug.Log("stealing" + this.gameObject.name);

        SetTrueStolen();
        otherScript.SetTrueStolen(); //set stolen variable to true for both players to prevent either from steal until OnCollisionExit

        BallAttach ballScript = otherScript.ballCarried.GetComponent <BallAttach>();

        if (ballScript != null) //get reference to the ball carried by other player
        {
            audioManagerScript.PlaySound("Steal");
            ballScript.AttachTo(this.gameObject);
        }

        otherScript.ReleaseBall();
    }