public void SpawnNewPunchBag()
    {
        GameObject obj = Instantiate(PunchBag, transform.position, transform.rotation);

        CurrentPunchBag = obj.GetComponent <PunchingBag>();
        CurrentPunchBag.Setup(this);
    }
示例#2
0
    /// <summary>
    /// Kick off something the player needs to interact with
    /// </summary>
    /// <param name="myHurdleIndex"></param>
    /// <param name="myHurdle"></param>
    /// <returns></returns>
    private IEnumerator KickOffHurdle(int myHurdleIndex, PunchingBag myHurdle, List <float> times, Transform start, Transform end)
    {
        bool madeYellow = false;

        float visualStartTime = times[myHurdleIndex] - beatRadiusVisualHint;
        float visualEndTime   = times[myHurdleIndex] + beatRadiusVisualHint;

        float inputStartTime = times[myHurdleIndex] - beatInputLead;
        float inputEndTime   = times[myHurdleIndex] + beatInputLag;

        bool inputSuccess = false;
        bool missed       = false;

        Command correctCode = Command.Fire;

        if (myHurdle.CorrectCommand == "up")
        {
            correctCode = Command.Up;
        }
        else if (myHurdle.CorrectCommand == "down")
        {
            correctCode = Command.Down;
        }
        else
        {
            Debug.LogError("unhandled code!");
        }

        while (currentTime < visualEndTime)
        {
            if (currentTime > inputStartTime && !madeYellow)
            {
                madeYellow = true;
                myHurdle.MakeReady();
            }

            // success
            if (currentTime > inputStartTime && currentTime < inputEndTime &&
                (CommandsStartedThisFrame.ContainsKey(correctCode)))
            {
                success.Play();
                inputSuccess = true;

                // make the hurdle green
                myHurdle.MakeCorrect();
                myHurdle.TakeDamage();

                // shout a success shout
                int successShoutIndex = Random.Range(0, successShouts.Count);
                if (lastSuccessShout == successShoutIndex)
                {
                    successShoutIndex++;
                    if (successShoutIndex >= successShouts.Count)
                    {
                        successShoutIndex = 0;
                    }
                }
                outputText.text  = successShouts[successShoutIndex];
                lastSuccessShout = successShoutIndex;
            }

            // miss..
            else if (currentTime > inputEndTime && !inputSuccess && !missed)
            {
                missed = true;

                // todo toss the hurdle
                myHurdle.MakeWrong();

                // shout a miss shout
                int missShoutIndex = Random.Range(0, missShouts.Count);
                if (lastMissShout == missShoutIndex)
                {
                    missShoutIndex++;
                    if (missShoutIndex >= missShouts.Count)
                    {
                        missShoutIndex = 0;
                    }
                }
                outputText.text = missShouts[missShoutIndex];
                lastMissShout   = missShoutIndex;

                numMistakes++;
                mistake.Play();
            }

            // the punching bag hurdle moves up and then down, it's at the end in middle time

            float hurdleProgress = (currentTime - visualStartTime) / (visualEndTime - visualStartTime);

            float prog = hurdleCurve.Evaluate(hurdleProgress);

            myHurdle.transform.position = Vector3.Lerp(start.position, end.position, prog);

            yield return(0);
        }

        if (numMistakes > allowedMistakes)
        {
            StartCoroutine(Failure());
        }

        yield return(new WaitForSeconds(0.2f));
    }