示例#1
0
    // Update is called once per frame
    void Update()
    {
        // State machine for casting and casting UI
        switch (currentState)
        {
        case fishingState.powering:
            // This section updates the position of the indicator on the screen and underlying values
            if (currentPower >= maxPower)
            {
                powerMod = -1.0f;
            }
            else if (currentPower <= 0.0f)
            {
                powerMod = 1.0f;
            }

            currentPower += Time.deltaTime * powerMod;
            UpdatePowerBarPos();

            // Checks for the end to powering
            if (Input.GetMouseButtonDown(0) && shopState.IsGamePaused() == false)
            {
                currentState = fishingState.angling;

                // Disable power bar visuals & enable angle bar visuals
                powerBarParent.GetComponent <SpriteRenderer>().enabled    = false;
                powerBarIndicator.GetComponent <SpriteRenderer>().enabled = false;

                angleBarParent.GetComponent <SpriteRenderer>().enabled = true;
                angleBarIndicator.transform.GetChild(0).gameObject.GetComponent <SpriteRenderer>().enabled = true;

                powerPercentage = currentPower / maxPower;
            }
            break;

        case fishingState.angling:
            if (currentAngle >= maxAngle)
            {
                angleMod = -1.0f;
            }
            else if (currentAngle <= minAngle)
            {
                angleMod = 1.0f;
            }

            currentAngle += Time.deltaTime * 90.0f * angleMod;          // Increase the float in the middle here to increase speed
            //Debug.Log(currentAngle);


            angleBarIndicator.transform.rotation = Quaternion.Euler(0.0f, 0.0f, Mathf.Lerp(-90.0f, 90.0f, currentAngle / 180.0f));
            // Debug.Log(angleBarIndicator.transform.rotation.z);

            if (Input.GetMouseButtonDown(0) && shopState.IsGamePaused() == false)
            {
                // The angle and power are finalized
                angleBarParent.GetComponent <SpriteRenderer>().enabled = false;
                angleBarIndicator.transform.GetChild(0).gameObject.GetComponent <SpriteRenderer>().enabled = false;
                fishingRod.CastLine(1.0f - currentPower, currentAngle);
                currentState = fishingState.none;
            }

            break;

        case fishingState.none:
            // Checks if we need to start powering state
            if (Input.GetMouseButtonDown(0) && fishingRod.finiteState == FishingState.Inactive)
            {
                currentState = fishingState.powering;
                powerBarParent.GetComponent <SpriteRenderer>().enabled    = true;
                powerBarIndicator.GetComponent <SpriteRenderer>().enabled = true;
            }
            // Reels in the fishing rod faster if the mouse is clicked
            else if (fishingRod.finiteState == FishingState.Rising && Input.GetMouseButton(0))
            {
                fishingRod.HandleMouseDown();
            }
            break;

        default:
            break;
        }
    }