Пример #1
0
    private void Shoot()
    {
        AudioManager.PlayEnemyShoot();
        animate.AnimateToColorAndBack(Palette.EnemyColor, Color.red, .2f);
        Vector3    direction = (PlayerController.PlayerPosition - transform.position).normalized;
        GameObject missile   = Instantiate(projectile, ProjectileManager.myTransform);

        missile.transform.position = transform.position;
        missile.GetComponent <Missile>().Initialize(direction, projectileSpeed);
    }
Пример #2
0
    void Update()
    {
        if (inputDisabled)
        {
            _velocity = new Vector2();
            return;
        }

        float x = Input.GetAxis("Horizontal");
        float y = Input.GetAxis("Vertical");

        bool dash       = Input.GetKeyDown(KeyCode.JoystickButton18) || Input.GetKeyDown(KeyCode.UpArrow);
        bool dashCancel = Input.GetKeyUp(KeyCode.JoystickButton18) || Input.GetKeyUp(KeyCode.UpArrow);

        bool fire = Input.GetAxisRaw("Fire") <= 0.0f;

        if (!fire)
        {
            shooting = false;
        }
        else if (fire && !shooting)
        {
            _animate.AnimateToColorAndBack(Palette.PlayerColor, Color.red, .05f);

            shooting = true;
            NotificationMaster.SendPlayerShootNotification();
            AudioManager.PlayEnemyShoot();

            //float direction = spriteFlipped ? -1 : 1;
            Vector2 direction = new Vector2(x, y).normalized;
            if (direction == Vector2.zero)
            {
                direction.x = spriteFlipped;
            }
            GameObject missile = Instantiate(projectile, ProjectileManager.myTransform);
            missile.transform.position = transform.position + Vector3.Scale(playerSize, direction.normalized);
            missile.GetComponent <Missile>().Initialize(direction.normalized, projectileSpeed);
        }

        // xbox

        /*float fireX = Input.GetAxis ("FireX");
         * float fireY = Input.GetAxis ("FireY");
         * if (Mathf.Abs(fireX) > .5f||Mathf.Abs(fireY) > .5f)
         *      fire = true;*/

        if (Mathf.Abs(x) > .3)
        {
            speed.x = x * runSpeed;
            if (spriteFlipped * x < 0)
            {
                FlipPlayer();
            }
        }
        else
        {
            speed.x = 0;
        }

        if (Mathf.Abs(y) > .3)
        {
            speed.y = y * runSpeed;
        }
        else
        {
            speed.y = 0;
        }


        // apply horizontal speed smoothing it. dont really do this with Lerp. Use SmoothDamp or something that provides more control
        var smoothedMovementFactor = 2 * groundDamping;        //_controller.isGrounded ? groundDamping : inAirDamping; // how fast do we change direction?

        _velocity = Vector2.Lerp(_velocity, speed, Time.deltaTime * smoothedMovementFactor);

        _controller.move(_velocity * Time.deltaTime);

        // grab our current _velocity to use as a base for all calculations
        _velocity = _controller.velocity;
    }