示例#1
0
    // Update is called once per frame
    void Update()
    {
        FaceMouse();

        if (Input.GetMouseButtonDown(0) && !shot && GameManager.instance.DidStart)
        {
            Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            if (mousePosition.x < transform.position.x + 4.25f)
            {
                mousePosition.x = transform.position.x + 4.25f;
            }

            if (mousePosition.y < transform.position.y + 4.25f)
            {
                mousePosition.y = transform.position.y + 4.25f;
            }

            float   powerBarPercent = powerBar.GetPowerBarPercent();
            Vector2 direction       = new Vector2(
                mousePosition.x - transform.position.x,
                mousePosition.y - transform.position.y
                );
            Vector2 power = direction.normalized * cannonPower * (0.5f + 0.5f * powerBarPercent);

            beaver.Activate();
            beaver.ShootOutOfCannon(new Vector2(power.x, power.y));
            powerBar.Deactivate();
            AudioSource audio = GetComponent <AudioSource>();
            audio.Play();
            aimer.SetActive(false);

            blastParticle[UpgradeManager.instance.GetCannonUpgradeNum()].Play();

            shot = true;
        }
    }