示例#1
0
 void Jump()
 {
     m_animator.SetTrigger("Jump");
     m_grounded = false;
     m_animator.SetBool("Grounded", m_grounded);
     m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
     m_groundSensor.Disable(0.2f);
 }
示例#2
0
 //Jump
 void Jump()
 {
     grounded = false;
     animator.SetTrigger("Jump");
     animator.SetBool("Grounded", grounded);
     playerBody.velocity = new Vector2(playerBody.velocity.x, jumpForce);
     groundSensor.Disable(0.2f);
 }
示例#3
0
    // Update is called once per frame
    void Update()
    {
        if (!m_isDead && movingEnable)
        {
            if (!m_grounded && m_groundSensor.State())
            {
                m_grounded = true;
                m_animator.SetBool("Grounded", m_grounded);
            }

            if (m_grounded && !m_groundSensor.State())
            {
                m_grounded = false;
                m_animator.SetBool("Grounded", m_grounded);
            }

            float inputX = Input.GetAxis("Horizontal");

            if (inputX > 0)
            {
                GetComponent <SpriteRenderer>().flipX = true;
                isWatchingLeft = false;
            }
            else if (inputX < 0)
            {
                GetComponent <SpriteRenderer>().flipX = false;
                isWatchingLeft = true;
            }
            // Move
            m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y);


            //Jump
            if (Input.GetKeyDown("space") && m_grounded)
            {
                m_grounded = false;
                m_animator.SetBool("Grounded", m_grounded);
                m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
                m_groundSensor.Disable(0.2f);
            }
            //Fight
            else if (Input.GetKeyDown("q"))
            {
                SpawnBullet();
            }
            //Run
            else if (Mathf.Abs(inputX) > Mathf.Epsilon)
            {
                m_animator.SetInteger("AnimState", 1);
            }
            //Idle
            else
            {
                m_animator.SetInteger("AnimState", 0);
            }
        }
    }
示例#4
0
    void Update()
    {
        if (!finished)
        {
            if (!m_grounded && m_groundSensor.State())
            {
                m_grounded = true;
                doubleJump = true;
                m_animator.SetBool("Grounded", m_grounded);
            }

            if (m_grounded && !m_groundSensor.State())
            {
                m_grounded = false;
                m_animator.SetTrigger("Jump");
                m_animator.SetBool("Grounded", m_grounded);
            }

            // -- Handle input and movement --
            float inputX = Input.GetAxis("Horizontal");
            sprite.flipX = inputX > 0;

            // Move
            m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y);

            //Jump
            if (Input.GetKeyDown("space") && (doubleJump))
            {
                if (m_grounded)
                {
                    m_grounded        = false;
                    m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
                    m_animator.SetTrigger("Jump");
                    m_animator.SetBool("Grounded", m_grounded);
                    m_groundSensor.Disable(0.5F);
                }
                else
                {
                    doubleJump        = false;
                    m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce / 2);
                }
            }

            //Run
            else if (Mathf.Abs(inputX) > 0.0F)
            {
                m_animator.SetInteger("AnimState", 2);
            }

            //Idle
            else
            {
                m_animator.SetInteger("AnimState", 0);
            }
        }
    }
示例#5
0
    // Update is called once per frame
    void Update()
    {
        //Check if character just landed on the ground
        if (!m_grounded && m_groundSensor.State())
        {
            m_grounded = true;
            m_animator.SetBool("Grounded", m_grounded);
        }

        //Check if character just started falling
        if (m_grounded && !m_groundSensor.State())
        {
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
        }

        // -- Handle input and movement --
        float inputX = Input.GetAxis("Horizontal");

        // Swap direction of sprite depending on walk direction
        if (inputX > 0)
        {
            transform.localScale = new Vector3(-1.0f, 1.0f, 1.0f);
        }
        else if (inputX < 0)
        {
            transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
        }

        // Move
        float targetVel;

        if (Input.GetKey("left"))
        {
            targetVel = -m_speed;
        }
        else if (Input.GetKey("right"))
        {
            targetVel = m_speed;
        }
        else
        {
            targetVel = 0;
        }
        m_body2d.velocity = Vector2.Lerp(m_body2d.velocity, new Vector2(targetVel, m_body2d.velocity.y), Time.deltaTime * m_acceleration);

        //Set AirSpeed in animator
        m_animator.SetFloat("AirSpeed", m_body2d.velocity.y);

        // -- Handle Animations --
        //Death
        if (Input.GetKeyDown("e"))
        {
            if (!m_isDead)
            {
                m_animator.SetTrigger("Death");
            }
            else
            {
                m_animator.SetTrigger("Recover");
            }

            m_isDead = !m_isDead;
        }

        //Hurt
        else if (Input.GetKeyDown("q"))
        {
            m_animator.SetTrigger("Hurt");
        }

        //Attack
        else if (Input.GetKeyDown("d"))
        {
            m_animator.SetTrigger("Attack");
        }

        //Change between idle and combat idle
        else if (Input.GetKeyDown("f"))
        {
            m_combatIdle = !m_combatIdle;
        }

        //Jump
        else if (Input.GetKeyDown("space") && m_grounded)
        {
            m_animator.SetTrigger("Jump");
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
            m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
            m_groundSensor.Disable(0.2f);
        }

        //Run
        else if (Mathf.Abs(inputX) > Mathf.Epsilon)
        {
            m_animator.SetInteger("AnimState", 2);
        }

        //Combat Idle
        else if (m_combatIdle)
        {
            m_animator.SetInteger("AnimState", 1);
        }

        //Idle
        else
        {
            m_animator.SetInteger("AnimState", 0);
        }
    }
示例#6
0
    // Update is called once per frame
    void Update()
    {
        //Check if character just landed on the ground
        if (!m_grounded && m_groundSensor.State())
        {
            m_grounded = true;
            m_animator.SetBool("Grounded", m_grounded);
        }

        //Check if character just started falling
        if (m_grounded && !m_groundSensor.State())
        {
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
        }

        // -- Handle input and movement --
        float inputX = Input.GetAxis("Horizontal");

        // Swap direction of sprite depending on walk direction
        if (inputX > 0)
        {
            GetComponent <SpriteRenderer>().flipX = true;
        }
        else if (inputX < 0)
        {
            GetComponent <SpriteRenderer>().flipX = false;
        }

        // Move
        m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y);

        //Set AirSpeed in animator
        m_animator.SetFloat("AirSpeed", m_body2d.velocity.y);

        // -- Handle Animations --
        //Death
        if (Input.GetKeyDown("e"))
        {
            if (!m_isDead)
            {
                m_animator.SetTrigger("Death");
            }
            else
            {
                m_animator.SetTrigger("Recover");
            }

            m_isDead = !m_isDead;
        }

        //Hurt
        else if (Input.GetKeyDown("q"))
        {
            m_animator.SetTrigger("Hurt");
        }

        //Attack
        else if (Input.GetMouseButtonDown(0))
        {
            m_animator.SetTrigger("Attack");
        }

        //Change between idle and combat idle
        else if (Input.GetKeyDown("f"))
        {
            m_combatIdle = !m_combatIdle;
        }

        //Jump
        else if (Input.GetKeyDown("space") && m_grounded)
        {
            m_animator.SetTrigger("Jump");
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
            m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
            m_groundSensor.Disable(0.2f);
        }

        //Run
        else if (Mathf.Abs(inputX) > Mathf.Epsilon)
        {
            m_animator.SetInteger("AnimState", 2);
        }

        //Combat Idle
        else if (m_combatIdle)
        {
            m_animator.SetInteger("AnimState", 1);
        }

        //Idle
        else
        {
            m_animator.SetInteger("AnimState", 0);
        }
    }
示例#7
0
    // Update is called once per frame
    void Update()
    {
        //Check if character just landed on the ground
        if (!m_grounded && m_groundSensor.State())
        {
            m_grounded = true;
            m_animator.SetBool("Grounded", m_grounded);
        }

        //Check if character just started falling
        if (m_grounded && !m_groundSensor.State())
        {
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
        }

        // -- Handle input and movement --
        float inputX = Input.GetAxis("Horizontal");

        // Swap direction of sprite depending on walk direction
        if (inputX > 0)
        {
            transform.localScale = new Vector3(-1.0f, 1.0f, 1.0f);
        }
        else if (inputX < 0)
        {
            transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
        }

        // Move
        m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y);

        //Set AirSpeed in animator
        m_animator.SetFloat("AirSpeed", m_body2d.velocity.y);

        // -- Handle Animations --
        //Death
        if (Input.GetKeyDown("e"))
        {
            if (!m_isDead)
            {
                m_animator.SetTrigger("Death");
            }
            else
            {
                m_animator.SetTrigger("Recover");
            }

            m_isDead = !m_isDead;
        }

        //Hurt
        else if (Input.GetKeyDown("q"))
        {
            m_animator.SetTrigger("Hurt");
            TakeDamage(30);
        }

        //Attack
        else if (Input.GetMouseButtonDown(0))
        {
            // m_animator.SetTrigger("Attack");
            if (Time.time >= nextAttackTime)
            {
                Attack();
                nextAttackTime = Time.time + 1f / attackRate;
            }
        }

        //Change between idle and combat idle
        else if (Input.GetKeyDown("f"))
        // m_combatIdle = !m_combatIdle;
        {
            ReleaseFullBar();
            Debug.Log("Bar was depleted!");
        }

        //Jump
        else if (Input.GetKeyDown("space") && m_grounded)
        {
            m_animator.SetTrigger("Jump");
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
            m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
            m_groundSensor.Disable(0.2f);
        }

        //Run
        else if (Mathf.Abs(inputX) > Mathf.Epsilon)
        {
            m_animator.SetInteger("AnimState", 2);
        }

        //Combat Idle
        else if (m_combatIdle)
        {
            m_animator.SetInteger("AnimState", 1);
        }

        //Idle
        else
        {
            m_animator.SetInteger("AnimState", 0);
        }
    }
    void Update()
    {
        //Dead
        if (HealthBar.kontrol == false)
        {
            if (kontrol)
            {
                this.GetComponent <PlayerMove>().enabled = false;
                this.GetComponent <Collider2D>().enabled = false;
                //AudioSource.PlayClipAtPoint(deadSound, Camera.main.transform.position);

                foreach (Transform child in this.transform)
                {
                    child.gameObject.SetActive(false);
                }

                kontrol = false;

                StartCoroutine("Restart");
                StartCoroutine("destroyBanner");
            }
        }

        timer += Time.deltaTime;
        if (!m_grounded && m_groundSensor.State())
        {
            m_grounded = true;
            m_animator.SetBool("Grounded", m_grounded);
        }

        if (m_grounded && !m_groundSensor.State())
        {
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
        }

        inputX = Input.GetAxis("Horizontal");

        if (inputX > 0)
        {
            GetComponent <SpriteRenderer>().flipX = true;
        }

        else if (inputX < 0)
        {
            GetComponent <SpriteRenderer>().flipX = false;
        }

        // Move
        m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y);

        //Set AirSpeed in animator
        m_animator.SetFloat("AirSpeed", m_body2d.velocity.y);

        //Attack
        //if (Input.GetMouseButtonDown(0))
        //{
        //    m_animator.SetTrigger("Attack");
        //    if (GetComponent<SpriteRenderer>().flipX == true)
        //    {
        //        StartCoroutine(ClearRightPos());
        //    }
        //    else
        //    {
        //        StartCoroutine(ClearLeftPos());
        //    }

        //}
        //Defans
        if (Input.GetKeyDown("f"))
        {
            m_combatIdle = !m_combatIdle;
        }
        //Jump
        else if (Input.GetKeyDown("space") && m_grounded || jumpClicked && m_grounded)
        {
            m_animator.SetTrigger("Jump");
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
            m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
            m_groundSensor.Disable(0.2f);
            jumpClicked = false;
        }
        //Run
        else if (Mathf.Abs(inputX) > Mathf.Epsilon)
        {
            m_animator.SetInteger("AnimState", 2);
        }

        //Combat Idle
        else if (m_combatIdle)
        {
            m_animator.SetInteger("AnimState", 1);
        }

        //Idle
        else
        {
            m_animator.SetInteger("AnimState", 0);
        }

        if (leftClicked)
        {
            MovePlayer(-1f);
        }
        if (rightClicked)
        {
            MovePlayer(1f);
        }
        if (attackClicked && timer > nextFire)
        {
            m_animator.SetTrigger("Attack");
            if (GetComponent <SpriteRenderer>().flipX == true)
            {
                //StartCoroutine(ClearRightPos());
                StartCoroutine(ClearLeftPos());
            }
            else
            {
                //StartCoroutine(ClearLeftPos());
                StartCoroutine(ClearRightPos());
            }

            attackClicked = false;
        }

        ultiTimer += Time.deltaTime;
    }
示例#9
0
文件: Bandit.cs 项目: Wrzonteq/PPzD
    // Update is called once per frame
    void Update()
    {
        if (input == null || m_isDead)
        {
            return;
        }
        //Check if character just landed on the ground
        if (!m_grounded && m_groundSensor.State())
        {
            m_grounded = true;
            m_animator.SetBool("Grounded", m_grounded);
            LandedEvent();
        }

        //Check if character just started falling
        if (m_grounded && !m_groundSensor.State())
        {
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
        }

        // -- Handle input and movement --
        var inputX = CanMove() ? input.GetHorizontalMove() : 0;

        // Swap direction of sprite depending on walk direction
        if (inputX > 0)
        {
            transform.localScale = new Vector3(-1.0f, 1.0f, 1.0f);
        }
        else if (inputX < 0)
        {
            transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
        }

        // Move
        m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y);

        //Set AirSpeed in animator
        m_animator.SetFloat("AirSpeed", m_body2d.velocity.y);

        if (postAttackCooldown > 0)
        {
            postAttackCooldown -= Time.deltaTime;
        }

        if (blockTimer <= 0 && postBlockCooldown > 0)
        {
            postBlockCooldown -= Time.deltaTime;
            IsBlocking         = false;
            m_combatIdle       = false;
        }

        if (blockTimer > 0)
        {
            blockTimer -= Time.deltaTime;
        }
        // -- Handle Animations --
        //Attack
        else if (input.Attack() && postAttackCooldown <= 0)
        {
            m_animator.SetTrigger("Attack");
            postAttackCooldown = 0.9f;
            AttackedEvent();
        }
        //Jump
        else if (input.Jump() && m_grounded)
        {
            m_animator.SetTrigger("Jump");
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
            m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
            m_groundSensor.Disable(0.2f);
            JumpedEvent();
        }
        else if (input.Block() && postBlockCooldown <= 0)
        {
            IsBlocking        = true;
            m_combatIdle      = true;
            postBlockCooldown = 1f;
            blockTimer        = blockDuration;
        }
        //Run
        if (Mathf.Abs(inputX) > Mathf.Epsilon)
        {
            m_animator.SetInteger("AnimState", 2);
        }
        //Combat Idle
        else if (m_combatIdle)
        {
            m_animator.SetInteger("AnimState", 1);
        }
        //Idle
        else
        {
            m_animator.SetInteger("AnimState", 0);
        }
    }
示例#10
0
    // Update is called once per frame
    void Update()
    {
        //Check if character just landed on the ground
        if (!m_grounded && m_groundSensor.State())
        {
            m_grounded = true;
            m_animator.SetBool("Grounded", m_grounded);
        }

        //Check if character just started falling
        if (m_grounded && !m_groundSensor.State())
        {
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
        }

        // -- Handle input and movement --
        float inputX = Input.GetAxis("Horizontal");

        if (!m_isDead)
        {
            // Swap direction of sprite depending on walk direction
            if (inputX > 0)
            {
                transform.localScale = new Vector3(-1.0f, 1.0f, 1.0f);
            }

            else if (inputX < 0)
            {
                transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
            }

            // Move
            m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y);
        }

        //Set AirSpeed in animator
        m_animator.SetFloat("AirSpeed", m_body2d.velocity.y);

        //Death
        //m_animator.SetTrigger("Death");
        //m_isDead = !m_isDead;

        //Hurt
        //m_animator.SetTrigger("Hurt");

        //Jump
        if (Input.GetKeyDown("space") && m_grounded && !m_isDead)
        {
            m_animator.SetTrigger("Jump");
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
            m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
            m_groundSensor.Disable(0.2f);
        }

        //Run
        else if (Mathf.Abs(inputX) > Mathf.Epsilon && !m_isDead)
        {
            m_animator.SetInteger("AnimState", 2);
        }

        //Combat Idle
        else if (m_combatIdle)
        {
            m_animator.SetInteger("AnimState", 1);
        }

        //Idle
        else
        {
            m_animator.SetInteger("AnimState", 0);
        }
    }
示例#11
0
文件: Player.cs 项目: Bacur/CMTRY
    void Update()
    {
        if (!_grounded && _groundSensor.State())
        {
            _grounded = true;
            _animator.SetBool("Grounded", _grounded);
        }

        if (_grounded && !_groundSensor.State())
        {
            _grounded = false;
            _animator.SetBool("Grounded", _grounded);
        }

        if (!_Dash)
        {
            inputX = Input.GetAxis("Horizontal");
        }

        Flip(inputX);


        _animator.SetFloat("AirSpeed", _body2d.velocity.y);

        /*
         * if (Input.GetKeyDown("e")) {
         *  if(!_isDead)
         *      _animator.SetTrigger("Death");
         *  else
         *      _animator.SetTrigger("Recover");
         *
         *  _isDead = !_isDead;
         * }
         */

        if (Input.GetKeyDown(KeyCode.LeftShift) && !_Dash)
        {
            _Dash     = true;
            _DashTime = Time.time + 0.3f;
        }
        else if (Input.GetMouseButtonDown(0) && _TimeToAttack < Time.time)
        {
            _animator.SetTrigger("Attack");
            _TimeToAttack = Time.time + _TimeReload;
        }

        else if (Input.GetKeyDown("f"))
        {
            _combatIdle = !_combatIdle;
        }

        else if (Input.GetKeyDown("space") && _grounded)
        {
            _animator.SetTrigger("Jump");
            _grounded = false;
            _animator.SetBool("Grounded", _grounded);
            _body2d.velocity = new Vector2(_body2d.velocity.x, _jumpForce);
            _groundSensor.Disable(0.2f);
        }

        else if (Mathf.Abs(inputX) > Mathf.Epsilon)
        {
            _animator.SetInteger("AnimState", 2);
        }

        else if (_combatIdle)
        {
            _animator.SetInteger("AnimState", 1);
        }

        else
        {
            _animator.SetInteger("AnimState", 0);
        }

        Move(inputX);
    }
示例#12
0
    void Update()
    {
        CalculateVelocity();
        HandleWallSliding();

        controller.Move(velocity * Time.deltaTime, directionalInput);

        if (controller.collisions.above || controller.collisions.below)
        {
            if (controller.collisions.slidingDownMaxSlope)
            {
                velocity.y += controller.collisions.slopeNormal.y * -gravity * Time.deltaTime;
            }
            else
            {
                velocity.y = 0;
            }
        }

        //Check if character just landed on the ground
        if (!m_grounded && m_groundSensor.State())
        {
            m_grounded = true;
            m_animator.SetBool("Grounded", m_grounded);
        }

        //Check if character just started falling
        if (m_grounded && !m_groundSensor.State())
        {
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
        }

        // -- Handle input and movement --
        float inputX = Input.GetAxis("Horizontal");

        // Swap direction of sprite depending on walk direction
        if (inputX > 0)
        {
            transform.localScale = new Vector3(-2.0f, 2.0f, 2.0f);
            timerStart           = true;
        }
        else if (inputX < 0)
        {
            transform.localScale = new Vector3(2.0f, 2.0f, 2.0f);
            timerStart           = true;
        }

        // Move
        m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y);

        //Set AirSpeed in animator
        m_animator.SetFloat("AirSpeed", m_body2d.velocity.y);

        // -- Handle Animations --
        //Death
        if (Input.GetKeyDown("e"))
        {
            if (!m_isDead)
            {
                m_animator.SetTrigger("Death");
            }
            else
            {
                m_animator.SetTrigger("Recover");
            }

            m_isDead = !m_isDead;
        }

        //Hurt
        else if (Input.GetKeyDown("q"))
        {
            m_animator.SetTrigger("Hurt");
        }

        //Attack
        else if (Input.GetMouseButtonDown(0))
        {
            m_animator.SetTrigger("Attack");
        }

        //Change between idle and combat idle
        else if (Input.GetKeyDown("f"))
        {
            m_combatIdle = !m_combatIdle;
        }

        //Jump
        else if (Input.GetKeyDown("space") && m_grounded)
        {
            m_animator.SetTrigger("Jump");
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
            m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
            m_groundSensor.Disable(0.2f);
        }

        //Run
        else if (Mathf.Abs(inputX) > Mathf.Epsilon)
        {
            m_animator.SetInteger("AnimState", 2);
        }

        //Combat Idle
        else if (m_combatIdle)
        {
            m_animator.SetInteger("AnimState", 1);
        }

        //Idle
        else
        {
            m_animator.SetInteger("AnimState", 0);
        }

        if (timerStart)
        {
            timeLeft -= Time.deltaTime;
        }

        if (timeLeft > 0)
        {
            var timer = GameObject.Find("Timer");
            timer.GetComponent <UnityEngine.UI.Text>().text = timeLeft.ToString();
        }

        if (timeLeft < 0 && !is_damaged)
        {
            GameObject player = GameObject.Find("Player");
            player.transform.position = new Vector3(22f, 10f, 0f);

            StartCoroutine(HitDrake());

            if (m_animator.GetCurrentAnimatorStateInfo(0).IsName("Attack"))
            {
                GameObject pvDrake      = GameObject.Find("HpDrake");
                var        imagePvDrake = pvDrake.GetComponent <UnityEngine.UI.Image>();

                imagePvDrake.fillAmount -= (float)m_item / 30;

                Reset(player);
            }
        }
    }
    // Update is called once per frame



    void Update()
    {
        if (Time.timeScale == 0f)
        {
            return;
        }


        parx  = 0;
        parx2 = 0;


        if (Input.GetKey(KeyCode.LeftArrow))
        {
            if (!myFx.isPlaying && isGrounded)
            {
                walk();
            }

            speedX = -horSpeed;
            parx   = -parxSpeed;
            parx2  = -parxSpeed2;



            if (speedX < 0 && isFacingRight)
            {
                Flip();
            }
        }



        else if (Input.GetKey(KeyCode.RightArrow))
        {
            if (!myFx.isPlaying && isGrounded)
            {
                walk();
            }

            speedX = horSpeed;
            parx   = parxSpeed;
            parx2  = parxSpeed2;



            if (speedX > 0 && !isFacingRight)
            {
                Flip();
            }
        }
        transform.Translate(speedX, 0, 0);
        speedX = 0;

        //Check if character just landed on the ground
        if (!m_grounded && m_groundSensor.State())
        {
            m_grounded = true;
            m_animator.SetBool("Grounded", m_grounded);
        }

        //Check if character just started falling
        if (m_grounded && !m_groundSensor.State())
        {
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
        }

        // второстепенное управление!
        float inputX = Input.GetAxis("Horizontal");

        // смена направления(устарело)
        //if (inputX > 0)
        //    GetComponent<SpriteRenderer>().flipX = true;
        //else if (inputX < 0)
        //  GetComponent<SpriteRenderer>().flipX = false;

        // Move
        // m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y);

        //Set AirSpeed in animator
        m_animator.SetFloat("AirSpeed", m_body2d.velocity.y);


        //Death
        if (Input.GetKeyDown("e"))
        {
            if (!m_isDead)
            {
                m_animator.SetTrigger("Death");
            }
            else
            {
                m_animator.SetTrigger("Recover");
            }

            m_isDead = !m_isDead;
        }
        if (lifeScriptAlf.lifeValue <= 0)
        {
            //      SoundDeath();
            // animator.SetBool("isDead", true);
            Invoke("death", deathDelay);
        }

        //дэмэдж
        //else if (Input.GetKeyDown("q"))


        //атака

        else if (Input.GetKeyDown("w"))
        {
            if (attackAnim == true)
            {
                attackAnim = false;
                m_animator.SetTrigger("Attack");
                Invoke("AttackResetAnim", 1);
                Invoke("SoundHit", attackSoundDelay);
            }

            Invoke("Attack", attackDelay);
        }


        //Смена позиции (не знаю еще для чгео)
        else if (Input.GetKeyDown("f"))
        {
            m_combatIdle = !m_combatIdle;
        }



        //прыжок
        else if (Input.GetKeyDown("space") && m_grounded)
        {
            SoundJump();
            m_animator.SetTrigger("Jump");
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
            m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
            m_groundSensor.Disable(0.2f);
        }

        //Run
        else if (Mathf.Abs(inputX) > Mathf.Epsilon)
        {
            m_animator.SetInteger("AnimState", 2);
        }

        //Combat Idle
        else if (m_combatIdle)
        {
            m_animator.SetInteger("AnimState", 1);
        }

        //Idle
        else
        {
            m_animator.SetInteger("AnimState", 0);
        }
    }
示例#14
0
    // Update is called once per frame
    void Update()
    {
        //Check if character just landed on the ground
        if (!m_grounded && m_groundSensor.State())
        {
            m_grounded = true;
            m_animator.SetBool("Grounded", m_grounded);
        }

        //Check if character just started falling
        if (m_grounded && !m_groundSensor.State())
        {
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
        }

        // -- Handle input and movement --
        float inputX = Input.GetAxis("Horizontal");

        // Swap direction of sprite depending on walk direction
        if (inputX > 0)
        {
            GetComponent <SpriteRenderer>().flipX = true;
        }
        else if (inputX < 0)
        {
            GetComponent <SpriteRenderer>().flipX = false;
        }

        // Move
        m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y);

        //Set AirSpeed in animator
        m_animator.SetFloat("AirSpeed", m_body2d.velocity.y);

        // -- Handle Animations --
        //Death
        if (currentHealth <= 0)
        {
            if (m_isDead == false)
            {
                m_animator.SetTrigger("Death");
                m_isDead = true;
                Debug.Log("You dead");
                Time.timeScale = 0f;
                FindObjectOfType <MenuBehaviour>().endGame();
            }
        }
        //keep the souce code for debug

        /*if (Input.GetKeyDown("e")) {
         *  if(!m_isDead)
         *      m_animator.SetTrigger("Death");
         *  else
         *      m_animator.SetTrigger("Recover");
         *
         *  m_isDead = !m_isDead;
         * }  */

        //Hurt
        else if (Input.GetKeyDown("q"))
        {
            m_animator.SetTrigger("Hurt");
        }


        //Hurt
        else if (Input.GetKeyDown("s"))
        {
            m_animator.SetTrigger("Hurt");
        }

        //Attack
        else if (Input.GetKeyDown("z"))
        {
            //Attack timer so the player wont go crazy
            if (Time.time >= nextAttackTime)
            {
                attack();
                nextAttackTime = Time.time + 1f / atkRate;
            }
            //m_attack.Update();
        }

        /*
         * else if(Input.GetMouseButtonDown(0)) {
         *  m_animator.SetTrigger("Attack");
         * }
         */

        //Change between idle and combat idle
        else if (Input.GetKeyDown("f"))
        {
            m_combatIdle = !m_combatIdle;
        }

        //Jump
        else if (Input.GetKeyDown("space") && m_grounded)
        {
            m_animator.SetTrigger("Jump");
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
            m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
            jumpAudio.Play();
            m_groundSensor.Disable(1.3f);
        }



        /* else if (Input.GetKeyDown("space") && coll.IsTouchingLayers(ground))
         * {
         *  m_animator.SetBool("Jump", true);
         * }
         */
        //Run
        else if (Mathf.Abs(inputX) > Mathf.Epsilon)
        {
            m_animator.SetInteger("AnimState", 2);
        }

        //Combat Idle
        else if (m_combatIdle)
        {
            m_animator.SetInteger("AnimState", 1);
        }


        else if (Input.GetKeyDown(KeyCode.Space))
        {
            //TakeDamage(20);  debug only
        }

        //Idle
        else
        {
            m_animator.SetInteger("AnimState", 0);
        }
    }
示例#15
0
    // Update is called once per frame
    void Update()
    {
        if (!m_isDead)
        {
            //Check if character just landed on the ground
            if (!m_grounded && m_groundSensor.State())
            {
                m_grounded = true;
                m_animator.SetBool("Grounded", m_grounded);
            }

            //Check if character just started falling
            if (m_grounded && !m_groundSensor.State())
            {
                m_grounded = false;
                m_animator.SetBool("Grounded", m_grounded);
            }

            // -- Handle input and movement --
            float inputX = Input.GetAxis("Horizontal");

            // Swap direction of sprite depending on walk direction
            if (inputX > 0)
            {
                GetComponent <SpriteRenderer>().flipX = true;
            }
            else if (inputX < 0)
            {
                GetComponent <SpriteRenderer>().flipX = false;
            }

            // Move
            m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y);

            //Set AirSpeed in animator
            m_animator.SetFloat("AirSpeed", m_body2d.velocity.y);


            if (m_grounded && inputX != 0)
            {
                if (!footsteps.isPlaying)
                {
                    footsteps.Play();
                }
            }
            else
            {
                if (footsteps.isPlaying)
                {
                    footsteps.Stop();
                }
            }
            // -- Handle Animations --

            //Attack
            if (click)
            {
                if (power == 0)
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        if (timeStamp <= Time.time)
                        {
                            m_animator.SetTrigger("Attack");
                            isAttacking = true;
                            Invoke("stopAttacking", 1f);
                            timeStamp = Time.time + cooldown;
                            slashAudio.Play();
                        }
                    }
                }
                else if (power == 1)
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        if (timeStamp <= Time.time)
                        {
                            m_speed = 40f;
                            m_animator.SetTrigger("Dash");
                            isAttacking = true;
                            Invoke("stopAttacking", 0.2f);
                            timeStamp = Time.time + cooldown;
                            dashAudio.Play();
                        }
                    }
                }
                else if (power == 2)
                {
                    if (Input.GetMouseButton(0))
                    {
                        if (timeStamp <= Time.time)
                        {
                            if (!m_grounded)
                            {
                                m_body2d.velocity     = new Vector2(m_body2d.velocity.x, 0);
                                m_speed               = 10f;
                                m_body2d.gravityScale = 12f;
                                m_animator.SetTrigger("Dash");
                                isAttacking = true;
                                if (!glideAudio.isPlaying)
                                {
                                    glideAudio.Play();
                                }
                            }
                            else
                            {
                                m_animator.SetTrigger("Attack");
                                isAttacking = true;
                                Invoke("stopAttacking", 1f);
                                timeStamp = Time.time + cooldown;
                                slashAudio.Play();
                            }
                        }
                    }
                    if (m_grounded)
                    {
                        glideAudio.Stop();
                    }
                    else if (Input.GetMouseButtonUp(0))
                    {
                        stopAttacking();
                        timeStamp = Time.time + cooldown;
                        glideAudio.Stop();
                    }
                }
                else if (power == 3)
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        if (timeStamp <= Time.time)
                        {
                            m_animator.SetTrigger("Attack");
                            isAttacking = true;
                            Invoke("stopAttacking", 1f);
                            timeStamp = Time.time + cooldown;
                            slashAudio.Play();
                        }
                    }
                }
                else if (power == 4)
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        if (timeStamp <= Time.time)
                        {
                            if (firstTime)
                            {
                                GlobalVariables.setFrozenTime(true);
                                Invoke("unfreezeTime", 2.3f);
                                firstTime = false;
                                timeStamp = 0;
                                timeFreezeAudio.Play();
                            }
                            else
                            {
                                m_animator.SetTrigger("Attack");
                                isAttacking = true;
                                Invoke("stopAttacking", 1f);
                                timeStamp = Time.time + cooldown;
                                slashAudio.Play();
                            }
                        }
                    }
                }
            }
            else
            {
                if (power == 0)
                {
                    if (Input.GetKeyDown(KeyCode.Space))
                    {
                        if (timeStamp <= Time.time)
                        {
                            m_animator.SetTrigger("Attack");
                            isAttacking = true;
                            Invoke("stopAttacking", 1f);
                            timeStamp = Time.time + cooldown;
                            slashAudio.Play();
                        }
                    }
                }
                else if (power == 1)
                {
                    if (Input.GetKeyDown(KeyCode.Space))
                    {
                        if (timeStamp <= Time.time)
                        {
                            m_speed = 40f;
                            m_animator.SetTrigger("Dash");
                            isAttacking = true;
                            Invoke("stopAttacking", 0.2f);
                            timeStamp = Time.time + cooldown;
                            dashAudio.Play();
                        }
                    }
                }
                else if (power == 2)
                {
                    if (Input.GetKey(KeyCode.Space))
                    {
                        if (timeStamp <= Time.time)
                        {
                            if (!m_grounded)
                            {
                                m_body2d.velocity     = new Vector2(m_body2d.velocity.x, 0);
                                m_speed               = 10f;
                                m_body2d.gravityScale = 12f;
                                m_animator.SetTrigger("Dash");
                                isAttacking = true;
                                if (!glideAudio.isPlaying)
                                {
                                    glideAudio.Play();
                                }
                            }
                            else
                            {
                                m_animator.SetTrigger("Attack");
                                isAttacking = true;
                                Invoke("stopAttacking", 1f);
                                timeStamp = Time.time + cooldown;
                                slashAudio.Play();
                            }
                        }
                    }
                    if (m_grounded)
                    {
                        glideAudio.Stop();
                    }
                    else if (Input.GetKeyUp(KeyCode.Space))
                    {
                        stopAttacking();
                        timeStamp = Time.time + cooldown;
                        glideAudio.Stop();
                    }
                }
                else if (power == 3)
                {
                    if (Input.GetKeyDown(KeyCode.Space))
                    {
                        if (timeStamp <= Time.time)
                        {
                            m_animator.SetTrigger("Attack");
                            isAttacking = true;
                            Invoke("stopAttacking", 1f);
                            timeStamp = Time.time + cooldown;
                            slashAudio.Play();
                        }
                    }
                }
                else if (power == 4)
                {
                    if (Input.GetKeyDown(KeyCode.Space))
                    {
                        if (timeStamp <= Time.time)
                        {
                            if (firstTime)
                            {
                                GlobalVariables.setFrozenTime(true);
                                Invoke("unfreezeTime", 2.3f);
                                firstTime = false;
                                timeStamp = 0;
                                timeFreezeAudio.Play();
                            }
                            else
                            {
                                m_animator.SetTrigger("Attack");
                                isAttacking = true;
                                Invoke("stopAttacking", 1f);
                                timeStamp = Time.time + cooldown;
                                slashAudio.Play();
                            }
                        }
                    }
                }
            }


            //Jump
            if ((Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)) && (m_grounded || doubleJump))
            {
                if (power == 3 && !doubleJump)
                {
                    doubleJump = true;
                }
                else if (doubleJump)
                {
                    doubleJump = false;
                    doubleJumpAudio.Play();
                }
                m_animator.SetTrigger("Jump");
                m_grounded = false;
                m_animator.SetBool("Grounded", m_grounded);
                m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
                m_groundSensor.Disable(0.2f);
            }

            //Run
            else if (Mathf.Abs(inputX) > Mathf.Epsilon)
            {
                m_animator.SetInteger("AnimState", 2);
            }

            //Idle
            else
            {
                m_animator.SetInteger("AnimState", 0);
            }


            if (m_grounded)
            {
                doubleJump = false;
            }
        }
    }
示例#16
0
    // Update is called once per frame
    void Update()
    {
        //Check if character just landed on the ground
        if (!m_grounded && m_groundSensor.State())
        {
            m_grounded = true;
            m_animator.SetBool("Grounded", m_grounded);
        }

        //Check if character just started falling
        if (m_grounded && !m_groundSensor.State())
        {
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
        }

        // // -- Handle input and movement --
        // float inputX = Input.GetAxis("Horizontal");

        // // Swap direction of sprite depending on walk direction
        // if (inputX > 0)
        //     transform.localScale = new Vector3(-1.0f, 1.0f, 1.0f);
        // else if (inputX < 0)
        //     transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);

        // Move
        float distance = Vector2.Distance(target.position, transform.position);

        if (distance <= lookRadius)
        {
            TargetInRange = true;
            //transform.LookAt(target);
            //m_body2d.transform.Translate(Vector2.left * m_speed * Time.fixedDeltaTime, myTansfrom);

            transform.position = Vector3.MoveTowards(transform.position, new Vector3(target.position.x, transform.position.y, -5), m_speed * Time.deltaTime);

            //m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y);
        }
        else
        {
            TargetInRange = false;
        }
        //Set AirSpeed in animator
        m_animator.SetFloat("AirSpeed", m_body2d.velocity.y);

        // -- Handle Animations --
        //Death
        if (EnemyHealth <= 0)
        {
            m_animator.SetTrigger("Death");
            DestroyGameObject();
            // else
            //m_animator.SetTrigger("Recover");

            //m_isDead = !m_isDead;
        }

        //Hurt
        // else if (Input.GetKeyDown("q"))
        //     m_animator.SetTrigger("Hurt");

        //Attack


        //Change between idle and combat idle
        // else if (Input.GetKeyDown("f"))
        //     m_combatIdle = !m_combatIdle;

        //Jump
        if (TargetInRange && knightMoement.jumped)
        {
            Debug.Log("jumping");
            m_animator.SetBool("jump1", true);
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
            m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
            m_groundSensor.Disable(0.2f);
        }
        else
        {
            m_animator.SetBool("jump1", false);
        }

        if (TargetInRange)
        {
            m_animator.SetBool("Attack1", true);
            GameObject E_sword = Instantiate(Enemy2Sowrd, E2_SowrdPoint.position, Quaternion.identity);
            Destroy(E_sword, 0.1f);
        }
        else
        {
            m_animator.SetBool("Attack1", false);
        }

        //Run
        // else if (Mathf.Abs(inputX) > Mathf.Epsilon)
        //     m_animator.SetInteger("AnimState", 2);

        // //Combat Idle
        // else if (m_combatIdle)
        //     m_animator.SetInteger("AnimState", 1);

        // //Idle
        // else
        //     m_animator.SetInteger("AnimState", 0);
    }