Exemplo n.º 1
0
    protected override void Shoot()
    {
        PlayerProjectile projectile = ProjectileFactory.CreateProjectile(ProjectileType.PLAYER) as PlayerProjectile;

        projectile.transform.position = shootPosition.position;
        projectile.Launch(shootPosition.forward, ShoudProjectileRecochet(), GameField);
    }
    void LaunchProjectile(PlayerProjectile prefab_p)
    {
        PlayerProjectile p = GameObject.Instantiate(prefab_p, weaponBlasterPoint.position, Quaternion.identity);

        p.fpsControllerCore = this;
        p.Launch(fpsCamera.transform.forward, runSpeed + 4);
    }
Exemplo n.º 3
0
    protected void Update()
    {
        if (isDead)
        {
            return;
        }

        float move = Input.GetAxis("Horizontal") * moveSpeed;

        transform.Translate(Vector3.right * (Time.deltaTime * move), Space.World);

        if (IsGrounded())
        {
            canDoubleJump = true;
        }

        if (Input.GetButtonDown("Fire2"))
        {
            if (IsGrounded())
            {
                rigidbody2d.velocity = Vector2.up * jumpVelocity;
                JumpEvent?.Invoke();
            }
            else if (canDoubleJump && unlockDoubleJump)
            {
                rigidbody2d.velocity = Vector2.up * jumpVelocity;
                canDoubleJump        = false;
            }
        }

        if (attacking)
        {
            if (Time.time > (attackTimer + 0.3f))
            {
                m_PlayerMelee.Enabled = false;
                attacking             = false;
            }
        }

        if (Input.GetButtonDown("Fire3") && !attacking)
        {
            //Debug.LogFormat("Fire3");
            attackTimer = Time.time;
            attacking   = true;
            m_PlayerMelee.Launch(transform.position, m_PlayerMelee.speed, direction);
            AttackEvent?.Invoke(AttackPattern.Melee);
        }

        if (dashing)
        {
            if (Time.time > (dashTimer + 1.0f))
            {
                dashing = false;
            }
        }

        if (Input.GetButtonDown("Jump") && unlockDash && !dashing && !attacking)
        {
            //Debug.LogFormat("Jump");
            dashTimer = Time.time;
            dashing   = true;

            if (direction)
            {
                RaycastHit2D raycastHit2d = Physics2D.Raycast(transform.position, Vector2.right, 6f, wallsLayerMask);
                if (raycastHit2d)
                {
                    float dashDistance = raycastHit2d.distance;
                    transform.position += new Vector3(dashDistance, 0.0f, 0.0f);
                }
                else
                {
                    transform.position += new Vector3(5.0f, 0.0f, 0.0f);
                }
            }
            else
            {
                RaycastHit2D raycastHit2d = Physics2D.Raycast(transform.position, Vector2.left, 6f, wallsLayerMask);
                if (raycastHit2d)
                {
                    float dashDistance = raycastHit2d.distance;
                    transform.position += new Vector3(-dashDistance, 0.0f, 0.0f);
                }
                else
                {
                    transform.position += new Vector3(-5.0f, 0.0f, 0.0f);
                }
            }

            DashEvent?.Invoke();
        }

        if (shooting)
        {
            if (Time.time > (shootTimer + 1.0f))
            {
                shooting = false;
            }
        }

        if (Input.GetButtonDown("Fire1") && unlockShooting && !shooting)
        {
            //Debug.LogFormat("Fire1");
            m_PlayerProjectile.Launch(transform.position, m_PlayerProjectile.speed, direction);
            shootTimer = Time.time;
            shooting   = true;
            AttackEvent?.Invoke(AttackPattern.Projectile);
        }

        if (Input.GetAxis("Horizontal") > 0.1f && !direction)
        {
            direction = true;
            m_PlayerMelee.transform.localPosition = new Vector3(0.1f, 0.01f, 0.0f);
            return;
        }

        if (Input.GetAxis("Horizontal") < -0.1f && direction)
        {
            direction = false;
            m_PlayerMelee.transform.localPosition = new Vector3(-0.1f, 0.01f, 0.0f);
            return;
        }

        isMoving = Mathf.Abs(Input.GetAxis("Horizontal")) > 0.1;
    }