コード例 #1
0
    //has the instance attack
    private void attack(Collider2D collider, float dam, float cooldown, bool shouldStun)
    {
        //tests if the player is in attack range
        if (isPlayerInRange(collider))
        {
            playerHitBox.gameObject.GetComponent <ControllerPlayer> ().damage(dam);
            //tests if shouls be stunned
            if (shouldStun)
            {
                playerHitBox.gameObject.GetComponent <ControllerPlayer>().stun(heavyStunTime);
            }
        }

        //sets the cooldown
        this.cooldown       = cooldown;
        isRunningFromAttack = true;

        //plays sound
        ASound.playAttackSound();
    }
コード例 #2
0
    //updates before physics updates
    void FixedUpdate()
    {
        //tests of time to next attack is being used
        if (!(timeToNextAttack <= 0))
        {
            timeToNextAttack -= Time.deltaTime;
            //tests if enough time went by
            if (timeToNextAttack <= 0)
            {
                canMove = true;
            }
        }

        //defualt slow is off
        isSlowed = false;

        //tests if should be slowed
        if (timeSlowedLeft > 0)
        {
            timeSlowedLeft -= Time.deltaTime;
            if (timeSlowedLeft <= 0)
            {
                isSlowed = false;
            }
            else
            {
                isSlowed = true;
            }
        }

        //variables for speed in each direction
        float vertical   = 0.0f;
        float horizontal = 0.0f;

        //tests if player is allowed to move
        if (canMove)
        {
            //checks if paused pressed
            if (buttonListen.isPressed(ButtonType.PAUSE))
            {
                //pauses game and stops player
                PauseMenuControl.pause();
                return;
            }

            //gets the angle of how the stick was moved
            horizontal = Stick.Horizontal();
            vertical   = Stick.Vertical();

            //checks attack buttons
            if (buttonListen.isPressed(ButtonType.ATTACK_LIGHT) && timeToNextAttack <= 0)
            {
                attack(lightAttack, lightAttackDamage, false);
                animator.SetTrigger("lightattack");
                timeToNextAttack = 1;
                ASound.playAttackSound();
            }

            if (buttonListen.isPressed(ButtonType.ATTACK_HEAVY) && timeToNextAttack <= 0)
            {
                attack(heavyAttack, heavyAttackDamage, true);
                animator.SetTrigger("heavyattack");
                timeToNextAttack = 2;
                canMove          = false;
                ASound.playAttackSound();
            }

            //Ammo selector checks
            if (buttonListen.isPressed(ButtonType.AMMO_PRIMARY))
            {
                setActiveAmmoPrimary(true);
            }

            if (buttonListen.isPressed(ButtonType.AMMO_SECONDARY))
            {
                setActiveAmmoPrimary(false);
            }
        }


        //checks ranged stick
        //if player is aiming
        if (isAiming())
        {
            //slows player movement
            isSlowed = true;

            //calculates trajectory
            calculateTrajectoryStart(out powerPrev, out isLeftPrev, out slopePrev);

            //draws trajectory line
            lineRender.gameObject.SetActive(true);
            shootCon.drawTrajectory(transform.position, powerPrev, slopePrev, isLeftPrev, lineRender);
        }
        //if player has attempted to shoot
        if (shouldShoot())
        {
            //shoots in trajectory using previous settings
            lineRender.gameObject.SetActive(false);

            //checks if ammo is left
            if (getActiveSelect().canConsume(1))
            {
                //shoots
                shootCon.shoot(transform.position, powerPrev, slopePrev, isLeftPrev, gameObject);
                //updates counter
                getActiveSelect().consume(1);
            }
        }

        //set variable for speed(in each direction) needed to move
        moveDirection = new Vector2(horizontal, vertical);

        //if slowed reduces the speed
        if (isSlowed)
        {
            moveDirection -= (moveDirection * slowPerCent);
        }

        //sets the animation speed variable
        moveDirection *= speed;

        //gets total speed in float
        float speedmove = horizontal + vertical;

        //changes direction sprite is facing

        //checks for facing right and changes to move left (negative value(speed) is facing left)
        if (transform.localScale.x > 0)
        {
            if (speedmove < 0)
            {
                //sets facing direction to the left
                Vector3 scale = gameObject.transform.localScale;
                scale.Set(gameObject.transform.localScale.x * -1, gameObject.transform.localScale.y, gameObject.transform.localScale.z);
                gameObject.transform.localScale = scale;
            }
            //checks for facing left and changes to move right
        }
        else if (transform.localScale.x < 0)
        {
            if (speedmove > 0)
            {
                //sets facing direction to the right
                Vector3 scale = gameObject.transform.localScale;
                scale.Set(gameObject.transform.localScale.x * -1, gameObject.transform.localScale.y, gameObject.transform.localScale.z);
                gameObject.transform.localScale = scale;
            }
        }

        //gets absolute value of speedmove
        speedmove = Mathf.Abs(speedmove);

        //sets animator speed parameter
        animator.SetFloat("speed", speedmove);

        //sets velocity for movement
        controller.velocity = moveDirection;
    }