Esempio n. 1
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);
            }
        }
    }
Esempio n. 2
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);
            }
        }
    }
Esempio n. 3
0
    // Update is called once per frame
    void Update()
    {
        if (!IsHit && !IsHited)
        {
            var Hor = Input.GetAxis("Horizontal");

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

            if (Input.GetKeyDown(KeyCode.Z) && mSensor_Bandit.State() && !isAttacking)
            {
                this.GetComponent <Rigidbody2D>().velocity = new Vector2(this.GetComponent <Rigidbody2D>().velocity.x, JumpHigth);
            }

            if (Input.GetKey(KeyCode.X) && mSensor_Bandit.State() && !isAttacking && !IsHited)
            {
                if (!isAttacking)
                {
                    StartCoroutine(Attack());
                }
            }
            else if (!mSensor_Bandit.State() && !isAttacking && !IsHited)
            {
                IsGrounded = true;
                animator.SetTrigger("Jump");
                animator.SetBool("Grounded", !mSensor_Bandit.State());
            }
            else if (Mathf.Abs(Hor) > Mathf.Epsilon)
            {
                animator.SetInteger("AnimState", 2);
            }
            else
            {
                animator.SetInteger("AnimState", 0);
            }

            if (!isAttacking)
            {
                if (Hor != 0)
                {
                    this.GetComponent <Rigidbody2D>().velocity = new Vector2(Hor * speed, this.GetComponent <Rigidbody2D>().velocity.y);
                }
                else
                {
                    this.GetComponent <Rigidbody2D>().velocity = new Vector2(0, this.GetComponent <Rigidbody2D>().velocity.y);
                }
            }
        }
    }
Esempio n. 4
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 moveX = -1;

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

        // Move


        m_body2d.velocity = new Vector2(moveX * m_speed, m_body2d.velocity.y);


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

        // m_animator.SetTrigger("Run");
        // -- Handle Animations --
        //Death

        //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
    }
Esempio n. 5
0
    void Update()
    {
        //Check if character just landed on the ground
        if (!grounded && groundSensor.State())
        {
            grounded = true;
            animator.SetBool("Grounded", grounded);
        }

        //Check if character just started falling
        if (grounded && !groundSensor.State())
        {
            grounded = false;
            animator.SetBool("Grounded", 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
        rb.velocity = new Vector2(inputX * speed, rb.velocity.y);


        // -- Handle Animations --
        // -----------------------

        //Run
        if (Mathf.Abs(inputX) > Mathf.Epsilon)
        {
            animator.SetInteger("AnimState", 2);
        }
        //Idle
        else
        {
            animator.SetInteger("AnimState", 0);
        }
        // -----------------------
    }
Esempio n. 6
0
    void Update()
    {
        if (attacking)
        {
            if (attackTimer > 0)
            {
                attackTimer -= Time.deltaTime;
            }
            else
            {
                attacking = false;
            }
        }
        //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);
        }

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



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

        //Idle
        else
        {
            m_animator.SetInteger("AnimState", 0);
        }
    }
 private void Jump()
 {
     if (m_groundSensor.State())
     {
         m_body2d.velocity = new Vector2(m_body2d.velocity.x, jumpForce);
     }
     else if (m_wallSensor.State())
     {
         transform.localScale = new Vector2(transform.localScale.x * -1, 1);
         m_wallJump           = true;
         Invoke("SetWallJumpToFalse", 0.08f);
     }
 }
Esempio n. 8
0
    // 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);
        }
    }
Esempio n. 9
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);
        }
    }
Esempio n. 10
0
    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);
    }
Esempio n. 11
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);
        }
    }
Esempio n. 13
0
    void Update()
    {
        facingRight = GetComponent <SpriteRenderer>().flipX;
        isAttacking = animator.GetCurrentAnimatorStateInfo(0).IsName("Attack");
        float inputX = Input.GetAxis("Horizontal");

        if (currentHealth <= 0)
        {
            switchToDeath();
        }

        if (!isAttacking)
        {
            SwordAttackDone();
        }

        if (!grounded && groundSensor.State())
        {
            grounded = true;
            animator.SetBool("Grounded", grounded);
        }

        if (grounded && !groundSensor.State())
        {
            grounded = false;
            animator.SetBool("Grounded", grounded);
        }

        // Swap direction of sprite depending on walk direction

        if (!isDead && !isAttacking)
        {
            if (inputX > 0)
            {
                GetComponent <SpriteRenderer>().flipX = true;
            }
            else if (inputX < 0)
            {
                GetComponent <SpriteRenderer>().flipX = false;
            }
        }

        // Jump
        if ((Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) && !isAttacking && grounded && !isDead)
        {
            Jump();
        }

        // -- Handle Animations --
        //Recover
        if (Input.GetKeyDown("e"))
        {
            if (isDead)
            {
                currentHealth = maxHealth;
                isDead        = false;
                animator.SetTrigger("Recover");
            }
        }
        //Attack
        if (Input.GetKey("space") && !isAttacking && !isDead)
        {
            animator.SetTrigger("Attack");
        }

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

        //Combat Idle
        if (combatIdle)
        {
            animator.SetInteger("AnimState", 1);
        }

        //Idle
        if (!Input.anyKey)
        {
            animator.SetInteger("AnimState", 0);
        }
    }
Esempio n. 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 (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);
        }
    }
    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;
    }
Esempio n. 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 = SimpleInput.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");
        }

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

        //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);
        }
    }
Esempio n. 17
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;
            }
        }
    }
Esempio n. 18
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);
        }
    }
Esempio n. 19
0
    private void Update()
    {
        //constantly running
        m_animator.SetInteger("AnimState", 2);

        //check if character just landed on 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);
        }

        //move enemy
        transform.Translate(Vector2.left * speed * Time.deltaTime);
        //get information on whether ground is detected at character edge of platform
        RaycastHit2D groundInfo = Physics2D.Raycast(groundDetection.position, Vector2.down, 100f);

        //no ground found/platform end or bounds reached
        if (groundInfo.collider == false)
        {
            changeDirection();
        }
        ////Combat Idle
        //if (m_combatIdle)
        //    m_animator.SetInteger("AnimState", 1);
        ////Idle
        //else
        //    m_animator.SetInteger("AnimState", 0);

        //TEST enemy attack
        //if (Input.GetKeyDown("b"))
        //    m_animator.SetTrigger("Attack");

        //Attack AI
        Vector3 forward = transform.TransformDirection(Vector3.forward) * 10;

        Debug.DrawRay(transform.position, forward, Color.green);

        //check distance between self and player, is player close enough to trigger melee attack?
        float distToPlayer = Vector3.Distance(transform.position, playerTarget.transform.position);

        //RaycastHit2D close = Physics2D.CircleCast(transform.position, 100, Vector2.up);
        //Debug.Log(distToPlayer);
        //if player is within attack range
        if (distToPlayer < attackRange)
        {
            //Debug.Log("in distance");
            //Check enough time passed since last attack
            if (Time.time > lastAttackTime + attackDelay)
            {
                //play attack animation
                m_animator.SetTrigger("Attack");

                //send message to player to take damagea
                playerTarget.SendMessage("TakeDamage", damage, SendMessageOptions.RequireReceiver);

                //record time attacked ***Time.time;
                lastAttackTime = Time.time;
            }
        }
    }
Esempio n. 20
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");
         *
         * //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);
         */
    }
Esempio n. 21
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);
        }
    }
Esempio n. 22
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);
        }
    }
Esempio n. 23
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);
    }