コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        // For debugging only
        // charge = maxCharge;
        // threshold = maxCharge - maxCharge / 5;

        if (Input.GetButtonDown("Flashlight") && firstPress)
        {
            firstPress = false;

            if (!isOn)
            {
                spotlight.SetActive(true);
                click.Play();
                isOn = true;
            }
            else
            {
                spotlight.SetActive(false);
                click.Play();
                isOn = false;
            }
        }

        // if (Input.GetKeyDown(KeyCode.E))
        // {
        //     battery.RestoreBattery();
        //     charge = maxCharge;
        //     threshold = maxCharge - maxCharge / 5;
        // }

        if (isOn && charge > 0)
        {
            charge -= deltaCharge * Time.deltaTime;
            spotlight.GetComponent <Light>().range = maxRange * charge / maxCharge;

            if (charge <= threshold)
            {
                battery.DecreaseBattery();
                threshold -= maxCharge / 5;
            }
        }


        if (Input.GetButtonUp("Flashlight"))
        {
            firstPress = true;
        }

        spriteMask.SetActive(isOn);
    }