Пример #1
0
 // Update is called once per frame
 void Update()
 {
     transform.rotation   = Quaternion.Euler(lockPos, lockPos, lockPos);
     grounded             = Physics2D.IsTouchingLayers(myCollider, whatIsGround);
     myRigidbody.velocity = new Vector2(moveSpeed, myRigidbody.velocity.y);
     if (grounded)
     {
         if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0))
         {
             myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
         }
     }
     if (Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0))
     {
         if (jumpTimeCounter > 0)
         {
             myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
             jumpTimeCounter     -= Time.deltaTime;
         }
     }
     if (Input.GetKeyUp(KeyCode.Space) || Input.GetMouseButtonUp(0))
     {
         jumpTimeCounter = 0;
     }
     if (grounded)
     {
         jumpTimeCounter = jumpTime;
     }
     myAnimator.SetFloat("Speed", myRigidbody.velocity.x);
     myAnimator.SetBool("Grounded", grounded);
 }
Пример #2
0
    public void PlayerMovement()
    {
        float horizontal = Input.GetAxis("Horizontal");

        if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.A))
        {
            animator.SetBool("Run", true);
        }

        if (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.A))
        {
            animator.SetBool("Run", false);
        }

        transform.Translate(horizontal * speed * speed * Time.deltaTime, 0f, 0f);

        bool grounded = Physics2D.IsTouchingLayers(playerCollider, ground);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (grounded)
            {
                rigidBody.velocity = new Vector2(rigidBody.velocity.x, _jumpSpeed);
            }
        }

        animator.SetBool("Jump", grounded);
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        transform.Translate(dir * Time.deltaTime, Space.World);

        if (Physics2D.IsTouchingLayers(mycol, top))
        {
            dir = new Vector3(-1, -4, 0);
            //	Debug.Log ("top");
            transform.rotation = Quaternion.Euler(0, 180.0f, 0.0f);
        }
        else if (Physics2D.IsTouchingLayers(mycol, left))
        {
            dir = new Vector3(2, 0, 0);
            //Debug.Log("left");
            transform.rotation = Quaternion.Euler(0, 0.0f, 0.0f);
        }
        else if (Physics2D.IsTouchingLayers(mycol, right))
        {
            dir = new Vector3(-2, 3, 0);
            //Debug.Log("right");
            transform.rotation = Quaternion.Euler(0, 180.0f, 0.0f);
        }
        else if (Physics2D.IsTouchingLayers(mycol, bottom))
        {
            dir = new Vector3(-2, 4, 0);
            //Debug.Log("bot");
            transform.rotation = Quaternion.Euler(0, 180.0f, 0.0f);
        }
    }
Пример #4
0
 // Update is called once per frame
 void Update()
 {
     if (Physics2D.IsTouchingLayers(GetComponent <BoxCollider2D>(), 1 << LayerMask.NameToLayer("Objects")))
     {
         SceneManager.LoadScene(0);
     }
 }
Пример #5
0
    // Update is called once per frame
    void Update()
    {
        playerMovement();

        ground = Physics2D.IsTouchingLayers(mycollider, matchground);

        jump = Input.GetKeyDown("space");

        if (ground == true) //if we're on the floor
        {
            if (jump)
            {
                rg.AddForce(Vector2.up * jumpNumber);
            }
        }



        hadooken = Input.GetKeyDown("g");


        myanimator.SetBool("hadooken", hadooken);
        myanimator.SetBool("jump", jump);
        myanimator.SetBool("ground", ground);
        myanimator.SetFloat("Speed", Mathf.Abs(h));
    }
Пример #6
0
    // Update is called once per frame
    void Update()
    {
        myRigidBody.velocity = new Vector2(moveSpeed, myRigidBody.velocity.y);

        grounded = Physics2D.IsTouchingLayers(myCollider, whatIsGround);

        if (Input.GetKeyDown(KeyCode.UpArrow) && grounded)
        {
            myRigidBody.velocity = new Vector2(myRigidBody.velocity.x, jumpForce);
        }

        if (Input.GetKey(KeyCode.UpArrow))
        {
            if (jumpTimeCounter > 0)
            {
                myRigidBody.velocity = new Vector2(myRigidBody.velocity.x, jumpForce);
                jumpTimeCounter     -= Time.deltaTime;
            }
        }

        if (Input.GetKeyUp(KeyCode.UpArrow))
        {
            jumpTimeCounter = 0;
        }

        if (grounded)
        {
            jumpTimeCounter = jumpTime;
        }

        //myAnimator.SetFloat("Speed", myRigidBody.velocity.x);
        //myAnimator.SetBool("Grounded", grounded);
    }
Пример #7
0
    // Update is called once per frame
    void Update()
    {
        isGrounded = Physics2D.IsTouchingLayers(coll, ground);

        rb.velocity = new Vector2(moveSpeed, rb.velocity.y);

        animator.SetTrigger("isWalking");

        fJumpPressedRemember -= Time.deltaTime;

        if (Input.GetMouseButtonDown(0))
        {
            fJumpPressedRemember = fJumpPressedRememberTime;
        }
        if ((fJumpPressedRemember > 0) && isGrounded)
        {
            fJumpPressedRemember = 0;
            rb.velocity          = new Vector2(rb.velocity.x, jumpHeight);
            animator.SetTrigger("isJumping");
            source.PlayOneShot(clip[2]);//call jump sound
        }
        if (Input.GetMouseButtonUp(0))
        {
            if (rb.velocity.y > 0)
            {
                rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * newJump);
            }
        }
        if (Input.GetKeyDown("escape"))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
        }
    }
Пример #8
0
    void Update()
    {
        grounded           = Physics2D.IsTouchingLayers(myCollider, whatIsGround);
        rigidBody.velocity = new Vector2(0, rigidBody.velocity.y);

        if (Input.GetKeyDown(KeyCode.Space) && grounded)
        {
            rigidBody.velocity = new Vector2(0, jumpSpeed);
        }

        if (GetComponent <Rigidbody2D>().velocity.y > 0 && !Input.GetKey(KeyCode.Space))
        {
            GetComponent <Rigidbody2D>().velocity += Physics2D.gravity * (fallMultiplier) * Time.deltaTime;
        }

        if (!grounded)
        {
            myAnimator.SetInteger("State", 2);
        }
        else if (shooting)
        {
            myAnimator.SetInteger("State", 1);
        }
        else if (shooting)
        {
            myAnimator.SetInteger("State", 3);
        }
        else
        {
            myAnimator.SetInteger("State", 0);
        }
    }
Пример #9
0
    // Update is called once per frame
    void Update()
    {
        grounded            = Physics2D.IsTouchingLayers(playerCollider, groundMask);
        dead                = Physics2D.IsTouchingLayers(playerCollider, deathMask);
        playerBody.velocity = new Vector2(speed, playerBody.velocity.y);

        /*if (dead) {
         *      // Stop game loop
         *      Time.timeScale = 0;
         *      print ("Game Over");
         *
         *      // Restarting the game
         *      if (Input.GetKey (KeyCode.Space) || Input.GetMouseButtonDown (0)) {
         *              Application.LoadLevel (0);
         *              Time.timeScale = 1;
         *      }
         * }*/

        if ((Input.GetKey(KeyCode.Space) || Input.GetMouseButtonDown(0)) && grounded)
        {
            playerBody.velocity = new Vector2(playerBody.velocity.x, jumpForce);
        }

        speed += aceleration;
    }
Пример #10
0
    void Update()
    {
        //Handle oscillation of lava drop
        Child.position = transform.position + transform.right * oscillator;
        oscillator    += Time.deltaTime * oscDir * 0.5f;
        if (oscillator > .05f)
        {
            oscDir = -1;
        }
        if (oscillator < -.05f)
        {
            oscDir = 1;
        }
        if (Physics2D.IsTouchingLayers(collideCheck, Despawn) &&
            (Mathf.Abs(transform.position.x - transform.parent.position.x) > tileLength ||
             Mathf.Abs(transform.position.y - transform.parent.position.y) > tileLength))
        {
            GameObject SpawnDrop = Instantiate(DespawnPrefab, new Vector3(transform.position.x, transform.position.y, 0), this.transform.rotation);
            SpawnDrop.transform.parent = this.gameObject.transform.parent;
            Destroy(this.gameObject);
        }
        float setYRotation = -((int)(this.gameObject.transform.rotation.eulerAngles.z / 90) - 1) % 2;
        float setXRotation = ((int)(this.gameObject.transform.rotation.eulerAngles.z / 90) - 2) % 2;

        m_Rigidbody2D.velocity = new Vector2(setXRotation * 2.5f, setYRotation * 2.5f);
    }
Пример #11
0
    // Update is called once per frame
    void Update()
    {
        ground = Physics2D.IsTouchingLayers(micolision, whatisground);

        if (velocidadenx < 22)
        {
            if (transform.position.x > acumuladordevelocidad)
            {
                acumuladordevelocidad += aumentadordevelocidad;
                velocidadenx           = velocidadenx * multiplicadorvelos;
            }
        }

        rb.velocity = new Vector2(velocidadenx, rb.velocity.y);

        if (Input.touchCount > 0 && salto < 1 && Input.GetTouch(0).phase == TouchPhase.Began)
        {
            rb.AddForce(new Vector2(0f, jumpForce), ForceMode2D.Force);
            salto++;
        }
        if (ground == true)
        {
            salto = 0;
        }
        miAnimacion.SetFloat("vSpeed", rb.velocity.y);
        miAnimacion.SetFloat("Speed", Mathf.Abs(velocidadenx));
        miAnimacion.SetBool("Ground", ground);
    }
Пример #12
0
    void Update()
    {
        // Ground check
        groundedCheck = Physics2D.IsTouchingLayers(myCollider, Platform);

        // Jump controls
        if (Input.GetKeyDown(KeyCode.Space) && groundedCheck == true)
        {
            rb.AddForce(new Vector2(0, 1) * jumpForce, ForceMode2D.Impulse);
            jumpSound.Play();
        }

        // Pause Button
        if (Input.GetKeyDown("escape"))
        {
            thePauseMenu.PauseGame();
        }

        // Check if player is still moving
        if (((rb.transform.InverseTransformDirection(rb.velocity).x < 0.1f && rb.transform.InverseTransformDirection(rb.velocity).x > -0.1f)) &&
            ((rb.transform.InverseTransformDirection(rb.velocity).y < 0.1f && rb.transform.InverseTransformDirection(rb.velocity).y > -0.1f)))
        {
            stoppedMoving = true;
            StartCoroutine(StoppedRestart());
        }
        else
        {
            stoppedMoving = false;
        }
    }
Пример #13
0
 // Update is called once per frame
 void Update()
 {
     this.grounded = Physics2D.IsTouchingLayers(GetComponent <BoxCollider2D>(), ground);
     this.HandleDirection();
     this.UpdateAnimatorVariables();
     this.framesLeft--;
 }
Пример #14
0
    // Update is called once per frame
    void Update()
    {
        isgrounded = Physics2D.IsTouchingLayers(myCollider, isGround);
        // 터치하면 점프
        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetKeyDown(KeyCode.Space))
        {
            if (isgrounded)
            {
                anim.SetTrigger("Jump");
                transform.Translate(Vector3.up * f_jumpValue * Time.deltaTime, Space.World);
                //rigidbody.velocity = new Vector2(rigidbody.velocity.x, f_jumpValue);
                //rigidbody.AddForce(transform.up * f_jumpValue, ForceMode2D.Impulse);
            }
        }
        currentHp -= Time.deltaTime * 3.0f;

        if (currentHp < 0 && isDie == false)
        {
            onDie();
        }

        float perc = currentHp / maxHp;

        health.value = perc;

        Debug.Log(perc);
    }
    // Update is called once per frame
    void Update()
    {
        //Only allow 1 jump
        grounded = Physics2D.IsTouchingLayers(collider2d, whatisGround);

        if (transform.position.x > speedMilestoneCount)
        {
            speedMilestoneCount += speedIncrease;

            speedIncrease = speedIncrease * speedMultiplier;
            moveSpeed     = moveSpeed * speedMultiplier;
        }

        rb2d.velocity = new Vector2(moveSpeed, rb2d.velocity.y);

        //PC CONTROLS
        if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0))
        {
            if (grounded)
            {
                rb2d.velocity = new Vector2(rb2d.velocity.x, jumpForce);
            }
        }

        theAnimator.SetFloat("Speed", rb2d.velocity.x);
        theAnimator.SetBool("Grounded", grounded);
    }
Пример #16
0
    void Update()
    {
        if (Input.GetAxis("Horizontal") > 0 && !facingRight)
        {
            FlipHorizontal();
        }
        else if (Input.GetAxis("Horizontal") < 0 && facingRight)
        {
            FlipHorizontal();
        }

        isGrounded = Physics2D.IsTouchingLayers(this.gameObject.GetComponent <Collider2D>(), groundItems);

        isJumping = !isGrounded;
        playerAnimator.SetBool("isJumping", isJumping);

        if (isGrounded)
        {
            isDoubleJump = false;
        }

        playerVelocity = GetComponent <Rigidbody2D>().velocity;

        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            CharacterJump();
        }

        if (Input.GetButtonDown("Jump") && !isGrounded && !isDoubleJump)
        {
            CharacterJump();
            isDoubleJump = true;
        }
    }
Пример #17
0
    // Update is called once per frame
    // All input detection and anything not directly related to physics here.
    void Update()
    {
        grounded = Physics2D.IsTouchingLayers(myCollider, ground);

        if (Physics2D.IsTouchingLayers(myCollider, bound))
        {
            if (Input.GetKeyDown(KeyCode.R))
            {
                RespawnPlayerDebug();
            }
        }

        if (grounded)
        {
            jumpTimeCounter = JUMP_TIME;
        }

        if (grounded && (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0)))
        {
            initialJump = true;
        }

        jumpButtonHeld = Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0);

        if (Input.GetKeyUp(KeyCode.Space) || Input.GetMouseButtonUp(0))
        {
            jumpButtonReleased = true;
        }

        myAnimator.SetBool("Grounded", grounded);
    }
Пример #18
0
    private void move(bool jump, bool crouch)
    {
        grounded = Physics2D.IsTouchingLayers(myBoxCollider, WhatIsGround);

        if (grounded && (Input.GetKey(KeyCode.LeftControl) || crouch))
        {
            myBoxCollider.size   = new Vector2((float)0.875, (float)0.9);
            myBoxCollider.offset = new Vector2((float)0, (float)0.459);
            moveSpeed            = (float)0.5 * baseMoveSpeed;
        }
        else
        {
            myBoxCollider.size   = new Vector2((float)0.828125, (float)1.148438);
            myBoxCollider.offset = new Vector2((float)0, (float)0.5742188);
            moveSpeed            = baseMoveSpeed;
        }


        myRigidbody.velocity = new Vector2(moveSpeed, myRigidbody.velocity.y);

        if (grounded && (Input.GetKeyDown(KeyCode.Space) || jump))
        {
            myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
        }

        myAnimator.SetFloat("moveSpeed", moveSpeed);
        myAnimator.SetBool("grounded", grounded);
        myAnimator.SetBool("crouch", crouch);
    }
Пример #19
0
    // Update is called once per frame
    void Update()
    {
        onGround = Physics2D.IsTouchingLayers(playerCollid, whatGround);

        playerRb.velocity = new Vector2(moveSpeed, playerRb.velocity.y);

        /*for (int i = 0; i < Input.touchCount; ++i)
         * {
         *  if(Input.GetTouch(i).phase == TouchPhase.Began)
         *  {
         *      playerRb.velocity = new Vector2(playerRb.velocity.x, jumpForce);
         *  }
         * }*/

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (onGround)
            {
                playerRb.velocity = new Vector2(playerRb.velocity.x, jumpForce);
            }
        }

        /*playerAnim.SetFloat("Speed", playerRb.velocity.x);
         * playerAnim.SetBool("OnGround", onGround);*/
    }
Пример #20
0
    void Update()
    {
        ground = Physics2D.IsTouchingLayers(myColider, isGround);
        if (Good)
        {
            Debug.Log("Good");
            gcount += 1;
            Good    = false;
        }
        if (Bad)
        {
            Debug.Log("bad");
            bcount += 1;
            Bad     = false;
        }
        player.velocity = new Vector2(movespeed, player.velocity.y);
        if (CrossPlatformInputManager.GetButtonDown("Jump"))
        {
            if (ground)
            {
                player.velocity = new Vector2(player.velocity.x, jumpForce);
            }
        }


        animator.SetFloat("speed", player.velocity.x);
        animator.SetBool("jump", ground);
    }
Пример #21
0
    void Update()
    {
        isGrounded = Physics2D.IsTouchingLayers(collider, 1 << LayerMask.NameToLayer("Ground"));

        if (isGrounded)
        {
            coyoteeCounter = coyoteeTime;
        }
        else
        {
            coyoteeCounter -= Time.deltaTime;
        }

        jumpBufferCount -= Time.deltaTime;

        if (jumpBufferCount >= 0 && coyoteeCounter > 0f)
        {
            rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
            jumpBufferCount = 0;
        }

        if (Time.time >= nextAttack)
        {
            if (controls.Player.Attack.triggered)
            {
                Attack();
                nextAttack = Time.time + 1f / attackRate;
            }
        }

        HesDeadJim();
    }
Пример #22
0
    // Update is called once per frame
    void Update()
    {
        //if (Input.GetKeyDown(KeyCode.D))
        //{
        //    rb.velocity = transform.right * speed;
        //}
        //if (Input.GetKeyDown(KeyCode.A))
        //{
        //    rb.velocity = transform.right * -speed;
        //}
        Vector3 horizontal = new Vector3(Input.GetAxis("Horizontal"), 0.0f, 0.0f);

        transform.position = transform.position + horizontal * 0.25f;

        Vector3 pos = Camera.main.WorldToViewportPoint(transform.position);

        pos.x = Mathf.Clamp01(pos.x);
        pos.y = Mathf.Clamp01(pos.y);
        transform.position = Camera.main.ViewportToWorldPoint(pos);


        grounded = Physics2D.IsTouchingLayers(col, groundsource);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (grounded)
            {
                rb.velocity = new Vector2(rb.velocity.x, forceAmount);
            }
        }
    }
Пример #23
0
    public void PlayerMovement()
    {
        isGrounded = Physics2D.IsTouchingLayers(hitbox, whatIsGround);
        anim.SetBool(groundedHash, isGrounded);

        // Jump movement
        rb.velocity = new Vector2(moveSpeed, rb.velocity.y);

        // Jump movement inputs
        if (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
        {
            // Jump limitations
            if (isGrounded)
            {
                rb.velocity = new Vector2(rb.velocity.x, jumpForce);
                anim.SetTrigger(jumpHash);
                FindObjectOfType <AudioManager>().Play("Jump");
                return;
            }
        }

        // Crouch
        if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))
        {
            anim.SetBool(crouchHash, true);
        }

        // Leaving crouched state
        if (Input.GetKeyUp(KeyCode.LeftControl) || Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.DownArrow) ||
            anim.GetCurrentAnimatorStateInfo(0).IsName("PlayerHurt"))
        {
            anim.SetBool(crouchHash, false);
        }
    }
Пример #24
0
    void FixedUpdate()
    {
        grounded = Physics2D.IsTouchingLayers(myCollider, isGround);

        //make the player able to jump
        if (Input.GetKey(KeyCode.Space) && grounded)
        {
            myRigidbody.AddForce(Vector3.up * (jumpPower * myRigidbody.mass * myRigidbody.gravityScale * 15.0f));
        }

        myAnimator.SetFloat("Speed", myRigidbody.velocity.x);
        myAnimator.SetBool("Grounded", grounded);

        //start of crouch function
        if (Input.GetKey(KeyCode.G) && grounded)
        {
            playerObject.GetComponent <BoxCollider2D>().enabled    = false;
            playerObject.GetComponent <CircleCollider2D>().enabled = true;
            myAnimator.SetBool("Crouch", true);
            Debug.Log("works");
        }
        if (Input.GetKey(KeyCode.F))
        {
            playerObject.GetComponent <CircleCollider2D>().enabled = false;
            playerObject.GetComponent <BoxCollider2D>().enabled    = true;
            myAnimator.SetBool("Crouch", false);
        }
    }
Пример #25
0
    // Update is called once per frame
    void Update()
    {
        _isGrounded          = Physics2D.IsTouchingLayers(myCollider, whatIsGround);
        myRigidBody.velocity = new Vector2((moveSpeed + speedIncreamentFactor * Time.deltaTime), myRigidBody.velocity.y);

        if (Input.GetKeyDown(KeyCode.Space) && _isGrounded)
        {
            soundManager.playJumpSound();
            _isJumping           = true;
            myRigidBody.velocity = new Vector2(moveSpeed, jumpForce);
        }

        if (Input.GetKey(KeyCode.Space) && _isJumping)
        {
            if (jumpForce < maxJumpForce)
            {
                jumpForce           += 0.2f;
                myRigidBody.velocity = new Vector2(moveSpeed, jumpForce);
            }
            else
            {
                _isJumping = false;
                jumpForce  = 12.0f;
            }
        }

        if (Input.GetKeyUp(KeyCode.Space) && _isJumping)
        {
            jumpForce  = 12.0f;
            _isJumping = false;
        }

        myAnimator.SetFloat("Speed", myRigidBody.velocity.x);
        myAnimator.SetBool("Grounded", _isGrounded);
    }
Пример #26
0
    private void OnFloor()
    {
        isGrounded = Physics2D.IsTouchingLayers(checkGround, whatsIsGround);


        //se inactiva el detector de piso cuando se salta y se activa nuevamente cuando va cayendo el jugador
        if (rb.velocity.y > 0 && hitA.collider == null && hitB.collider == null)
        {
            checkGround.enabled = false;
        }
        else if (hitA || hitB)
        {
            checkGround.enabled = true;
        }

        if (!isGrounded || rb.velocity.x != 0)
        {
            myColl.sharedMaterial = slide;
        }
        else
        {
            myColl.sharedMaterial = sticky;
        }

        if (!isGrounded && rb.velocity.y < 0 || !isGrounded && rb.velocity.y > 0)
        {
            StartCoroutine(SoundLand());
        }
    }
Пример #27
0
 void Update()
 {
     sliderTemp = GameObject.FindGameObjectWithTag("PlayerHealth");
     scoreTemp  = GameObject.FindGameObjectWithTag("Score");
     if (sliderTemp != null)
     {
         slider = sliderTemp.GetComponent <Slider> ();
     }
     if (scoreTemp != null)
     {
         score = scoreTemp.GetComponent <ScoreManager> ();
     }
     if (Physics2D.IsTouchingLayers(healthCollider, playerLayerMask))
     {
         if (playerHealth == null)
         {
             playerHealth = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHealth>();
         }
         slider = sliderTemp.GetComponent <Slider> ();
         if (slider.value >= 100)
         {
             score.IncreaseScore(1500);
         }
         playerHealth.IncreaseHealth(healthIncrease);
         Destroy(gameObject);
     }
     Physics2D.IgnoreLayerCollision(extrasLayerMask, enemyLayerMask);
     Physics2D.IgnoreLayerCollision(extrasLayerMask, extrasLayerMask);
 }
Пример #28
0
    // Update is called once per frame



    void FixedUpdate()
    {
        IsGrounded = Physics2D.IsTouchingLayers(BoxCollider, Ground);

        if (transform.position.x > SpeedMileStoneCount)
        {
            SpeedMileStoneCount   += SpeedIncreaceMileStone;
            SpeedIncreaceMileStone = SpeedIncreaceMileStone * SpeedMultiPlier;
            MoveSpeed = MoveSpeed * SpeedMultiPlier;
            ChangeBackgroundColor();
        }



        if ((Input.GetButton("Jump") || Input.GetMouseButton(0)) && IsGrounded)
        {
            mybody.velocity = new Vector3(mybody.velocity.x, JumpSpeed, 0f);
        }
        else if (IsGrounded == false)
        {
            //transform.Rotate (JumpRotate * -140 * Time.deltaTime);
            mybody.AddTorque(Tourge);
        }

        mybody.velocity = new Vector3(MoveSpeed, mybody.velocity.y, 0f);
    }
Пример #29
0
    void Update()
    {
        bool dead = Physics2D.IsTouchingLayers(playerCollider, deathGround);

        if (dead)
        {
            GameOver();
        }



        if (transform.position.x > mileStoneCount)
        {
            mileStoneCount += mileStone;
            speed           = speed * speedMultipier;
            mileStone      += mileStone * speedMultipier;
            Debug.Log("M" + mileStone + ", MC" + mileStoneCount + ", MS" + speed);
        }

        rigidBody.velocity = new Vector2(speed, rigidBody.velocity.y);

        bool grounded = Physics2D.IsTouchingLayers(playerCollider, ground);

        if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
        {
            if (grounded)
            {
                jumpSound.Play();
                rigidBody.velocity = new Vector2(rigidBody.velocity.x, jump);
            }
        }

        animator.SetBool("Grounded", grounded);
    }
Пример #30
0
 // Update is called once per frame
 void FixedUpdate()
 {
     if (HealthManager.health > 0)
     {
         enemyTouched = Physics2D.IsTouchingLayers(this.GetComponent <Collider2D>(), whoIsTheEnemy);
         if (enemyTouched && !invicible)
         {
             HealthManager.health -= 1;
             invincebilityCounter  = invicibilityTime;
             invicible             = true;
         }
         if (invicible && invincebilityCounter > 0)
         {
             StartCoroutine(PlayerBlink());
             invincebilityCounter -= Time.deltaTime;
         }
         else
         if (invincebilityCounter < 0)
         {
             invicible = false;
             if (playerSprite.enabled == false)
             {
                 playerSprite.enabled = true;
             }
         }
     }
     else
     {
         HealthManager.lifeCounter -= 1;
         dead = true;
     }
 }