Example #1
0
    public virtual void AIControl()
    {
        float velocity = 1.0f;

        //Moving left so invert velocity
        if (!entityMovement.facingRight)
        {
            velocity *= -1;
        }

        entityMovement.Movement(velocity);
    }
Example #2
0
    void Update()
    {
        if (GameManager.instance.isPaused())
        {
            return;
        }
        var shakingAmount = Input.acceleration.magnitude;

        if (shakingAmount > 1.5)
        {
            Special();
        }

        //if pressing jump button, call jump method to toggle boolean
        if (Input.GetButtonDown("Jump"))
        {
            entityMovement.Jump();
        }

        if (isJumping)
        {
            entityMovement.Jump();
            isJumping = false;
        }

        float hVelocity = CrossPlatformInputManager.GetAxis("Horizontal");

        if (hVelocity == 0)
        {
            hVelocity = Input.GetAxis("Horizontal");
            animator.ResetTrigger("Walk");
        }

        if (hVelocity != 0)
        {
            animator.SetTrigger("Walk");
        }

        //Call the base movement module method to handle movement
        entityMovement.Movement(hVelocity);

        //If the shift button is pressed
        if (Input.GetKeyDown(KeyCode.LeftShift))
        {
            Shoot();
        }

        //If the control button is pressed
        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            Melee();
        }

        //Set attack collider to enabled for the attack duration
        if (attacking == true)
        {
            meleeCollider.enabled = true;
            if ((Time.time - lastAttack) > attackDuration)
            {
                attacking = false;
                animator.ResetTrigger("Attack");
                meleeCollider.enabled = false;
            }
        }
        else
        {
            meleeCollider.enabled = false;
        }

        //Make player temporarily invulnerable after taking damage
        //Achieved by changing alpha values of the sprite
        if (temporaryInvulnerable)
        {
            if (rend.material.color.a == 1f && Time.time > opacitySwitchTime)
            {
                opacitySwitchTime = Time.time + 0.25f;
                setAlpha(0.5f);
            }
            if (rend.material.color.a == .5f && Time.time > opacitySwitchTime)
            {
                opacitySwitchTime = Time.time + 0.25f;
                setAlpha(1.0f);
            }
            if (Time.time > temporaryInvulnerableTime + invulnTime)
            {
                temporaryInvulnerable = false;
                setAlpha(1.0f);
            }
        }

        UpdateStats();
    }