示例#1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 position = transform.position;

        // get new horizontal position
        // float horizontalInput = Input.GetAxis("Horizontal");
        // if (horizontalInput < 0)
        // {
        //     position.x += horizontalInput * ConfigurationUtils.BurgerMoveUnitsPerSecond *
        //                   Time.deltaTime;
        // }
        // else if (horizontalInput > 0)
        // {
        //     position.x += horizontalInput * ConfigurationUtils.BurgerMoveUnitsPerSecond *
        //                   Time.deltaTime;
        // }

        // get new vertical position
        float verticalInput = Input.GetAxis("Vertical");

        if (verticalInput < 0 ||
            verticalInput > 0)
        {
            position.y += verticalInput * ConfigurationUtils.BurgerMoveUnitsPerSecond *
                          Time.deltaTime;
        }

        // move and clamp in screen
        transform.position = position;
        ClampInScreen();

        // reenable shooting on Fire1 axis release
        if (!canShoot &&
            Input.GetAxisRaw("Fire1") == 0)
        {
            cooldownTimer.Stop();
            canShoot = true;
        }

        // shoot french fries
        if (canShoot &&
            Input.GetAxisRaw("Fire1") != 0)
        {
            cooldownTimer.Run();
            canShoot = false;
            // Vector3 bulletPos = transform.position;
            // bulletPos.x += FrenchFriesPositionOffset;

            GameObject bullet1 = BulletPool.GetBullets();
            bullet1.transform.position = shootPos[0].transform.position;
            bullet1.SetActive(true);
            bullet1.GetComponent <Bullet>().StartMoving();

            GameObject bullet2 = BulletPool.GetBullets();
            bullet2.transform.position = shootPos[1].transform.position;
            bullet2.SetActive(true);
            bullet2.GetComponent <Bullet>().StartMoving();

            AudioManager.Play(AudioClipName.BurgerShot);
        }
    }