Exemplo n.º 1
0
    void FixedUpdate()
    {
        // Verificando se o jogador está sobre algum chão.
        grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, groundLayerMask);
        animator.SetBool("ground", grounded);

        // Pegando a movimentação.
        float movement = Input.GetAxis("Horizontal");

        // Setando para o animator o valor da movimentação.
        animator.SetFloat("hSpeed", Mathf.Abs(movement));

        // Setando para o animator o valor do pulo.
        animator.SetFloat("vSpeed", rigidbody2D.velocity.y);

        // Realizando a movimentação.
        rigidbody2D.velocity = new Vector2(movement * hMaxSpeed, rigidbody2D.velocity.y);

        if (movement > 0 && facing == FacingSide.LEFT)
        {
            facing = FacingSide.RIGHT;
            Flip();
        }
        else if (movement < 0 && facing == FacingSide.RIGHT)
        {
            facing = FacingSide.LEFT;
            Flip();
        }
    }
Exemplo n.º 2
0
    void FixedUpdate()
    {
        // Verificando se o jogador está sobre algum chão.
        grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, groundLayerMask);
        animator.SetBool ("ground", grounded);

        // Pegando a movimentação.
        float movement = Input.GetAxis ("Horizontal");

        // Setando para o animator o valor da movimentação.
        animator.SetFloat ("hSpeed", Mathf.Abs (movement));

        // Setando para o animator o valor do pulo.
        animator.SetFloat ("vSpeed", rigidbody2D.velocity.y);

        // Realizando a movimentação.
        rigidbody2D.velocity = new Vector2 (movement * hMaxSpeed, rigidbody2D.velocity.y);

        if (movement > 0 && facing == FacingSide.LEFT)
        {
            facing = FacingSide.RIGHT;
            Flip();
        }
        else if (movement < 0 && facing == FacingSide.RIGHT)
        {
            facing = FacingSide.LEFT;
            Flip();
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Throw the object in the direction of the facing side
    /// </summary>
    /// <param name="_facingSide">Facing side to look at</param>
    public virtual void Throw(FacingSide _facingSide, int _bonusDamages = 0)
    {
        if (!isGrab)
        {
            return;
        }

        gameObject.layer = LayerMask.NameToLayer("Object");

        rigidbody.isKinematic = false;
        transform.SetParent(null, true);

        Vector3 _force = Vector3.up;

        switch (_facingSide)
        {
        case FacingSide.Face:
            _force += -Vector3.forward;
            break;

        case FacingSide.Left:
            _force += -Vector3.right;
            break;

        case FacingSide.Right:
            _force += Vector3.right;
            break;

        case FacingSide.Back:
            _force += Vector3.forward;
            break;

        default:
            break;
        }

        rigidbody.velocity = _force * throwForce;
        bonusDamage        = _bonusDamages;

        bearer   = null;
        isGrab   = false;
        isThrown = true;
    }
Exemplo n.º 4
0
    //ON PHOTON SERIALIZE VIEW
    protected override void OnPhotonSerializeView(PhotonStream _stream, PhotonMessageInfo _messageInfo)
    {
        base.OnPhotonSerializeView(_stream, _messageInfo);

        if (_stream.isWriting)
        {
            _stream.SendNext(transform.position.x);
            _stream.SendNext(transform.position.y);
            _stream.SendNext(transform.position.z);
            _stream.SendNext((int)facingSide);
        }
        else if (_stream.isReading)
        {
            float      _posX = (float)_stream.ReceiveNext();
            float      _posY = (float)_stream.ReceiveNext();
            float      _posZ = (float)_stream.ReceiveNext();
            FacingSide _side = (FacingSide)_stream.ReceiveNext();
            netOnlinePosition = new Vector3(_posX, _posY, _posZ);
            ChangeSide(_side);
        }
    }
Exemplo n.º 5
0
 /// <summary>
 /// Makes the character change the side of the screen he's looking, its orientation
 /// </summary>
 /// <param name="_newSide">New orientation side of the character</param>
 protected void ChangeSide(FacingSide _newSide)
 {
     facingSide = _newSide;
     // Change Animator State
     CharacterAnimator.SetInteger("OrientationState", (int)_newSide);
 }