Exemplo n.º 1
0
    void Update()
    {
        if (Input.GetButtonDown("Cast Fishing Pole")) // F Key
        {
            ResetMinigame();
        }


        bool[] input = { Input.GetKeyDown(KeyCode.LeftArrow), Input.GetKeyDown(KeyCode.UpArrow), Input.GetKeyDown(KeyCode.DownArrow), Input.GetKeyDown(KeyCode.RightArrow),
                         Input.GetKeyDown(KeyCode.A),         Input.GetKeyDown(KeyCode.W),       Input.GetKeyDown(KeyCode.S),         Input.GetKeyDown(KeyCode.D) };

        for (int i = 0; i < arrowTargets.Length; i++)
        {
            //Input check
            if (input[i] || input[i + 4])
            {
                int score = -perfectScore;//Complete miss is negative perfect

                //Check for single target hit
                if (arrowTargets[i].Count > 0)
                {
                    GameObject target = arrowTargets[i][0];
                    //Absolute distance of target from base
                    float dist = Mathf.Abs(((Vector2)target.gameObject.transform.position - (Vector2)arrowBases[i].transform.position).magnitude);
                    //Make distance in units of target size
                    dist /= target.GetComponent <RectTransform>().rect.height;
                    if (dist <= perfectDistRatio)
                    {
                        score = perfectScore;
                    }
                    else if (dist <= perfectDistRatio * 2)
                    {
                        score = perfectScore / 2;
                    }
                    else if (dist <= perfectDistRatio * 4)
                    {
                        score = perfectScore / 4;
                    }

                    createWord((int)(dist / perfectDistRatio));

                    Destroy(target);
                    arrowTargets[i].RemoveAt(0);
                }

                currentScore += score;
            }

            //Move targets
            for (int j = 0; j < arrowTargets[i].Count; j++)
            {
                GameObject target = arrowTargets[i][j];
                target.transform.position -= new Vector3(0, canvas.pixelRect.height * Time.deltaTime / targetSpeed, 0);
                if (target.transform.position.y <= 0)
                {
                    //Target hit bottom, complete miss
                    currentScore -= perfectScore;
                    Destroy(target);
                    arrowTargets[i].RemoveAt(j);
                }
            }
        }

        //Update score text
        scoreText.text = "Score: " + currentScore;

        //logic for ending the scene
        if (currentScore >= catchScore)
        {
            PlayerPrefs.SetInt("Caught", PlayerPrefs.GetInt("Caught") + 1);
            fishBeingCaught.BuffPlayerStats(targetPlayer);
            ResetMinigame();
        }
        else if (currentScore <= releaseScore)
        {
            ResetMinigame();
        }

        //Send random target
        if (Time.time >= nextTargetTime)
        {
            SendArrow((int)(Random.value * arrowBases.Length));
            nextTargetTime = Time.time + Random.Range(targetFrequencyMin, targetFrequencyMax + 1) * targetFrequencyStep;
        }
    }