Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (_abilities.Count == 0 || _curAbility == null)
        {
            return;
        }

        if (_inCutscene)
        {
            return;
        }

        if (!_isWaiting && _player.IsTouchingGround() && !_player.HaveControl())
        {
            //if (!_inCutscene)
            //{
            _player.CanControl();
            //}
        }

        if (!_objInteraction.IsMovingObject())
        {
            if (Input.GetButtonDown("Switch"))
            {
                //int index = _abilities.IndexOf(_curAbility);
                //int newIndex = (index + 1) % _abilities.Count;
                //_curAbility = _abilities[newIndex];
            }
            else if (!_isWaiting && _player.IsTouchingGround() && Input.GetButtonDown("Invoke"))
            {
                if (!_curAbility.InUse() && _curAbility.CanUse())
                {
                    MetricManagerScript.instance.LogString("Gravity switched at position", _player.transform.position.ToString());
                    //_isWaiting = true;
                    _curAbility.UseAbility();
                    GameEvents.Instance.LayerUp();
                    //StartCoroutine(InvokeAbility());
                }
                else if (_curAbility.InUse() && _curAbility.CanUse())
                {
                    MetricManagerScript.instance.LogString("Gravity switched at position", _player.transform.position.ToString());
                    _curAbility.EndAbility();
                    GameEvents.Instance.LayerDown();
                }
            }
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        // check slope
        _isOnSlope = Physics2D.OverlapCircle(_groundCheck.position, _slopeCheckRadius, _whatIsSlope);

        // ground check

        _isGrounded = Physics2D.OverlapCircle(_groundCheck.position, _groundCheckRadius, _whatIsGround);

        if (!_isGrounded)
        {
            SoundManager.Instance.StopSFX("Walk");
        }

        if (_isGrounded && !_playerAnimator.GetBool("InAir"))
        {
            _playerAnimator.ResetTrigger("Jump");
            _playerAnimator.SetTrigger("ForceLand");
        }


        if (!_isOnSlope)
        {
            _playerAnimator.SetBool("InAir", !_isGrounded);
            if (_isGrounded == true)
            {
                _isJumping = false;
            }

            // check fall
            if (_isGrounded == false && _isJumping == false)
            {
                _playerAnimator.SetBool("InAir", true);
            }
        }
        else
        {
            if (_isGrounded)
            {
                _isJumping = false;
                _playerAnimator.SetBool("InAir", false);
                _playerAnimator.SetTrigger("LandFromSlope");
            }
            else
            {
                _playerAnimator.SetBool("InAir", true);
            }
            //else if (!_isGrounded && _isJumping)
            //{
            //    Debug.Log("falling.");
            //    _playerAnimator.SetBool("InAir", true);
            //}
            //else if (!_isGrounded && !_isJumping)
            //{
            //    Debug.Log("land.");
            //    _playerAnimator.SetBool("InAir", false);
            //}
        }



        if (!_haveControl)
        {
            SoundManager.Instance.StopSFX("Walk");
            return;
        }

        // turn player
        if (_input < 0)
        {
            if (!_obj.IsMovingObject())
            {
                this.transform.localScale = new Vector3(-_xScale, _yScale, 1);
            }
            _playerAnimator.SetBool("IsMoving", true);

            if (_isGrounded)
            {
                SoundManager.Instance.PlaySFX("Walk");
            }

            _wasWalking = true;
        }
        else if (_input > 0)
        {
            if (!_obj.IsMovingObject())
            {
                this.transform.localScale = new Vector3(_xScale, _yScale, 1);
            }
            _playerAnimator.SetBool("IsMoving", true);

            if (_isGrounded)
            {
                SoundManager.Instance.PlaySFX("Walk");
            }

            _wasWalking = true;
        }
        else
        {
            _playerAnimator.SetBool("IsMoving", false);

            SoundManager.Instance.StopSFX("Walk");

            _wasWalking = false;
        }

        // check jump
        if (_isGrounded == true && Input.GetButtonDown("Jump") && !Physics2D.OverlapCircle(_ceilingCheck.position, _ceilingCheckRadius, _whatIsGround))
        {
            if (!_obj.IsMovingObject())
            {
                _playerAnimator.SetTrigger("Jump");
                _playerAnimator.SetBool("InAir", true);
                SoundManager.Instance.StopSFX("Walk");
                SoundManager.Instance.PlaySFX("Jump");
                _isJumping = true;
                if (_gravityDown)
                {
                    _rb.velocity = new Vector2(_rb.velocity.x, _jumpForce);
                }
                else
                {
                    _rb.velocity = new Vector2(_rb.velocity.x, -_jumpForce);
                }
            }
        }
    }