Exemplo n.º 1
0
    private void OnCollisionEnter(Collision collision)
    {
        var collidedWith = collision.gameObject;

        //check if the collision was with the ball and make sure it wasn't thrown by another player if it was
        if (collidedWith.tag == "Ball" && !collidedWith.GetComponent <BallThrownState>().WasThrown)
        {
            _holdingState.StartHoldingBall(collidedWith); //Pick up the ball
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    private void Update()
    {
        if (isLocalPlayer)
        {
            var camera = Camera;

            // This will cast rays only against colliders in layer 9 (the ball's layer)
            int layerMask = 1 << 9;

            bool canHit = Physics.Raycast(camera.transform.position, camera.transform.forward, catchDistance, layerMask);

            var cursorColor = canHit
                ? Color.green
                : Color.red;

            CmdSetCursorColor(cursorColor);

            RaycastHit hit;

            // And if the "Fire2" input is pressed down
            if (canHit && _inputState.IsPressed(Buttons.CATCH) && _inputState.GetButtonHoldTime(Buttons.CATCH) == 0f)
            {
                // Need to find a way to use camera instead of this.transform.position, maybe a drag-in-drop or public variable to be set
                // Does the ray intersect any object in the ball layer
                bool caught = Physics.Raycast(camera.transform.position, camera.transform.forward, out hit, catchDistance, layerMask);

                if (caught)
                {
                    CmdStartCatchAnimation();

                    var ballCaughtMessage = new BallCaughtMessage
                    {
                        BallId     = hit.transform.gameObject.GetComponent <NetworkIdentity>().netId,
                        CaughtById = GetComponent <NetworkIdentity>().netId
                    };

                    LobbyManager.singleton.client.Send(MyMessageTypes.BallCaughtMessage, ballCaughtMessage);

                    _holdingState.StartHoldingBall(hit.transform.gameObject);
                }
            }
        }
    }