コード例 #1
0
ファイル: CPlayerTrap.cs プロジェクト: hansschaa/TestTaller2D
    public void OnUse(List <EItem> items)
    {
        //List<EItem> aux = new List<EItem>();
        for (int i = 0; i < inventory.slots.Length; i++)
        {
            if (inventory.getItemAmount(items[i]) > 0)
            //inventory.removeItem(items[i]);
            {
                inventory.removeItem(items[i]);
            }
            GameObject trap = Instantiate(input.objects[1], new Vector3(playerTransform.position.x, playerTransform.position.y, playerTransform.position.z), Quaternion.identity);
        }

        /*       for(int i = 0; i < aux.Count; i++)
         *     {
         *         inventory.removeItem(aux[i]);
         *     }
         *     //necesito guardarla en lista auxiliar y borrar esa lista
         */}
コード例 #2
0
    void Update()
    {
        if (cPlayerController.eInputMode != EInputMode.INDIALOG || GameStateManager.eGameState != EGameState.CUTSCENE)
        {
            #region "For events"

            if (player.GetButtonDown("UseSpirit"))
            {
                if (OnSpiritAbility != null)
                {
                    OnSpiritAbility();
                }
            }
            #endregion

            #region "Free movement Input"
            if (cPlayerController.eInputMode == EInputMode.FREEMOVEMENT)
            {
                if ((this.player.GetNegativeButtonDoublePressDown("Move Horizontal") ||
                     this.player.GetButtonDoublePressDown("Move Horizontal")) && !this.crouch && currentInteractiveObject == null &&
                    cPlayerController.m_Grounded)
                {
                    runSpeed = 2.5f;
                }


                else if ((this.player.GetNegativeButtonUp("Move Horizontal") || this.player.GetButtonUp("Move Horizontal")) &&
                         runSpeed == 2.5f)
                {
                    runSpeed = 1.5f;
                }


                horizontalMove = this.player.GetAxisRaw("Move Horizontal") * walkSpeed * runSpeed;
                verticalMove   = this.player.GetAxisRaw("Move Vertical");



                if (this.player.GetButtonDown("Jump") && !cPlayerController.m_OnWater && !crouch &&
                    cPlayerController.m_Grounded && currentInteractiveObject == null)
                {
                    jump = true;
                }



                //Agachar
                if (this.player.GetButtonDown("Down") && !crouch && currentInteractiveObject == null &&
                    !jump && !onLadder && !cPlayerController.m_OnWater && cPlayerController.m_Grounded)
                {
                    //runSpeed = 1.5f;
                    print("ingreso true");
                    _cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.CROUCH, "OnCrouch");
                    crouch = true;
                    anchimallenPosition.transform.position += new Vector3(1, -1, 0);
                }

                //Parar
                else if (this.player.GetButtonDown("Down") && cPlayerController.CheckGroundHeadCollision() == null)
                {
                    print("ingreso false");
                    crouch = false;
                    anchimallenPosition.transform.position += new Vector3(-1, 1, 0);
                }


                if (this.player.GetButtonDown("Throw") && cPlayerController.m_Grounded && !cPlayerController.m_OnWater && !crouch)
                {
                    //I check if there are rocks in my inventory
                    if (cInventario.getItemAmount(EItem.ROCK) > 0)
                    {
                        ResetVelocity();
                        this.proyectileProyection.SetActive(true);
                        cPlayerController.eInputMode = EInputMode.THROW;
                    }
                }
            }
            #endregion

            #region "Throw Input"
            else if (cPlayerController.eInputMode == EInputMode.THROW)
            {
                if (this.player.GetButtonDown("Cancel"))
                {
                    this.proyectileProyection.SetActive(false);
                    cPlayerController.eInputMode = EInputMode.FREEMOVEMENT;
                }

                if (this.player.GetButtonDown("Throw"))
                //&& stregthBarImage.fillAmount >= throwReduction)
                {
                    /*if(OnStrength != null)
                     *              OnStrength(-throwReduction);*/

                    cInventario.removeItem(EItem.ROCK);

                    float      angle = proyectileProyection.transform.rotation.eulerAngles.z;
                    GameObject rock  = Instantiate(objects[0], shootPosition.position, Quaternion.identity);

                    rock.GetComponent <Rigidbody2D>().AddForce(new Vector2(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad)) * throwForce);
                    Destroy(rock, 1.5f);


                    this.proyectileProyection.SetActive(false);
                    cPlayerController.eInputMode = EInputMode.FREEMOVEMENT;
                }
            }

            #endregion

            #region "Caught Object Input"
            if (currentInteractiveObject == null && !_onHide && !cPlayerController.m_OnWater)
            {
                RaycastHit2D hit = Physics2D.Raycast(new Vector2(transform.position.x, transform.position.y),
                                                     new Vector2(this.transform.localScale.x, 0), distanceToPush, m_WhatIsInteractiveObjects);

                if (hit.collider != null)
                {
                    print("entro porque el hit colisiono");
                    _auxMoveRock    = hit.collider.GetComponent <CMoveRock>();
                    _cMoveRock      = hit.collider.GetComponent <CMoveRock>();
                    _auxRigidbody2D = hit.collider.GetComponent <Rigidbody2D>();
                    _cMoveRock.ShowButton(true);


                    if (hit.collider.gameObject.CompareTag("MovilObject"))
                    //&& stregthBarImage.fillAmount >= pushReduction)
                    {
                        if (this.player.GetButtonDown("Action"))
                        {
                            _cMoveRock.ShowButton(false);
                            _auxMoveRock = null;
                            //runSpeed = .8f;
                            currentInteractiveObject = hit.collider.gameObject;
                            //GetComponent<FixedJoint2D>().connectedBody = currentInteractiveObject.GetComponent<Rigidbody2D>();
                            currentInteractiveObject.GetComponent <CapsuleCollider2D>().sharedMaterial = _cMoveRock.slipperyPhysicMaterial2D;


                            _cMoveRock.inInteraction = true;
                            _caughtToObject          = true;
                            //_auxRigidbody2D.constraints = RigidbodyConstraints2D.None;
                            _cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.PUSH, "OnPush");



                            //_auxRigidbody2D.constraints = RigidbodyConstraints2D.FreezeRotation;
                        }
                    }
                }

                else if (_cMoveRock != null)
                {
                    _cMoveRock.ShowButton(false);
                    currentInteractiveObject = null;
                }
            }

            else if (this.player.GetButtonUp("Action") && currentInteractiveObject != null)
            {
                DisengageObject();
            }

            #endregion

            #region "Swim Input"
            if (cPlayerController.eInputMode == EInputMode.SWIM)
            {
                verticalMove   = this.player.GetAxisRaw("Move Vertical");
                horizontalMove = this.player.GetAxisRaw("Move Horizontal") * walkSpeed * runSpeed;



                /*
                 * if(this.player.GetButtonDown("Dive") && !onDive)
                 * {
                 *      onDive = true;
                 *      cPlayerController.ChangeColliderOrientation(false);
                 *      //_rb.gravityScale = 4;
                 *
                 * }
                 *
                 * else if(this.player.GetButtonDown("Dive") && onDive)
                 * {
                 *      //_rb.gravityScale = 3;
                 *      onDive = false;
                 *      cPlayerController.ChangeColliderOrientation(true);
                 *      //horizontalMove = this.player.GetAxisRaw("Move Horizontal") * walkSpeed * diveSpeed;
                 * }*/

                if (verticalMove != 0)
                {
                    _rb.velocity = new Vector2(_rb.velocity.x, verticalMove * diveSpeed);
                }
            }
            #endregion

            #region "Hinge Input"
            if (cPlayerController.eInputMode == EInputMode.INHINGE)
            {
                if (this.player.GetNegativeButton("Move Horizontal"))
                {
                    this._rb.velocity -= new Vector2(.25f, 0);
                }

                else if (this.player.GetButton("Move Horizontal"))
                {
                    this._rb.velocity += new Vector2(.25f, 0);
                }

                if (this.player.GetButtonDown("Jump"))
                {
                    print("Jump");
                    cPlayerController.DisengageToHinge();
                }
            }



            #endregion

            #region "Update Animation"
            //Duda que serás mas cercano al optimo
            //Si hacer la validacion acá o en la clase CPlayerAnimationState
            //Pues envio datos que quizas no usaré porque la animacion a cambiar es la misma que la actual
            if (onDie)
            {
                _cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.WALK, "OnFlyDie");
            }

            else if (currentInteractiveObject == null)
            {
                if (this._cPlayerAnimation.ePlayerAnimation != EPlayerAnimationState.JUMP &&
                    !onLadder)
                {
                    if (!crouch && !cPlayerController.m_OnWater && cPlayerController.m_Grounded)                    //&& _rb.velocity.y <= 0)
                    {
                        if (horizontalMove != 0)
                        {
                            if (runSpeed == 2.5f)
                            {
                                _cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.RUN, "OnRun");
                                //_cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.RUN,"Run",2f,0,0.05f);
                                //_playerAnimator.SetTrigger("OnRun");
                            }


                            else if (runSpeed == 1.5f)
                            {
                                _cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.WALK, "OnWalk");
                                //_cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.WALK,"Walk",2f,0,0.05f);
                                //_playerAnimator.SetTrigger("OnWalk");
                            }
                        }



                        else
                        {
                            _cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.IDLE, "Idle");
                        }
                    }

                    else if (crouch)
                    {
                        _cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.CROUCH, "OnCrouch");
                    }
                }


                if (!onLadder)
                {
                    if (_rb.velocity.y < 0 && !cPlayerController.m_Grounded && !cPlayerController.m_OnWater)
                    {
                        _cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.FALL, "OnFall");
                    }

                    else if (cPlayerController.m_OnWater)
                    {
                        _cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.SWIM, "OnDive");
                    }

                    /*
                     * else if(cPlayerController.m_OnWater && this.onDive)
                     *      _cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.DIVE, "OnDive");	*/
                }

                if (jump)
                {
                    _cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.JUMP, "OnJump");
                }
            }

            else if (currentInteractiveObject != null)
            {
                if (cPlayerController.m_FacingRight && horizontalMove > 0 || !cPlayerController.m_FacingRight && horizontalMove < 0)
                {
                    _cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.PUSH, "OnPush");
                }

                else if (cPlayerController.m_FacingRight && horizontalMove < 0 || !cPlayerController.m_FacingRight && horizontalMove > 0)
                {
                    _cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.POP, "OnPop");
                }
            }

            if (onLadder)
            {
                _cPlayerAnimation.ChangeAnimation(EPlayerAnimationState.CLIMB, "OnClimb");
            }

            //Stop some animations if the horizontal input or vertical input is 0
            if ((horizontalMove == 0 && (int)_cPlayerAnimation.ePlayerAnimation < 3) ||
                (this.player.GetAxisRaw("Move Vertical") == 0 && (int)_cPlayerAnimation.ePlayerAnimation == 3) ||
                (cPlayerController.m_OnWater && horizontalMove == 0 && this.player.GetAxisRaw("Move Vertical") == 0))
            {
                _cPlayerAnimation.StopCurrentAnimation();
            }


            #endregion
            //print("Animacion: " + _cPlayerAnimation.ePlayerAnimation.ToString());
        }
    }