コード例 #1
0
    void Update()
    {
        if (cooldownTimer > 0)
        {
            cooldownTimer -= Time.deltaTime;
        }

        if (aimAmount >= 0)
        {
            if (increasing)
            {
                aimAmount += Time.deltaTime;
                if (aimAmount > maxAimTime)
                {
                    increasing = false;
                    aimAmount  = maxAimTime;
                }
            }
            else
            {
                aimAmount -= Time.deltaTime;
                if (aimAmount <= 0)
                {
                    increasing = true;
                    aimAmount  = 0;
                }
            }
        }
        if (cooldownTimer <= 0)
        {
            if (Input.GetKeyDown(KeyCode.E))
            {
                if (GC.numPotions > 0)
                {
                    print("aim " + target.gameObject);
                    target.gameObject.SetActive(true);
                    aimAmount  = 0;
                    increasing = true;
                }
                else if (GC.numPotions == 0)
                {
                    GC.NoPotionMessage();
                }
            }
        }

        if (Input.GetKeyUp(KeyCode.E) && cooldownTimer <= 0 && target.gameObject.activeSelf)
        {
            print("throw");
            Throw();
            target.gameObject.SetActive(false);
            aimAmount     = -10;
            cooldownTimer = cooldownAmount;
        }
        target.localPosition = new Vector3(0, targetY, Mathf.Lerp(throwDistanceMin, throwDistanceMax, aimAmount / maxAimTime));
        target.position      = new Vector3(target.position.x, targetY, target.position.z);
    }