public playerdata(gyroscope player)
 {
     level  = player.level;
     health = player.health;
     score  = player.score;
     hscore = player.hscore;
 }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        gyroscope GyroScript = face.GetComponent <gyroscope>();        //The gyroscope script is a component of the GameObject

        Gx = GyroScript.Gx;
        Gy = GyroScript.Gy;
        Gz = GyroScript.Gz;

        face.transform.Rotate(Gx * Time.deltaTime, Gy * Time.deltaTime, Gz * Time.deltaTime);

        var angles = face.transform.eulerAngles;

        // face.transform.eulerAngles refers to the x-y-z Euler Angles of the face

        xangle.text = ((int)angles.x).ToString();
        yangle.text = ((int)angles.y).ToString();
        zangle.text = ((int)angles.z).ToString();

        //___________________________________________________________________________

//	*** Step 1 ***
        if ((angles.y > 35) && (angles.y < 65) && (!flag1))
        {
            range1 = true;

            timer    -= Time.deltaTime;          // Timer decreases only when angle is within range
            inttime   = (int)timer;
            time.text = inttime.ToString();      // Changes content of timer's text box
            step.text = stepnum.ToString();      // Changes content of step number's text box

            todo.text = "Hold for 5 seconds";

            if (inttime == 0)                           // Condition for completion of a step

            {
                canvas1.SetActive(false);
                if (video1.isPlaying)
                {
                    video1.Stop();
                }
                video2.Play();

                flag1     = true;               // Flag that indicates Step 1 is complete
                todo.text = "Step 1 complete. Move the head vertically down by 120 degrees";

                stepnum++;
                timer   = duration;                             // Resetting timer
                inttime = duration;

                time.text = inttime.ToString();
                step.text = stepnum.ToString();                   // Updating contents of text boxes
            }
        }

        if ((range1) && ((angles.y < 35) || (angles.y > 65)))           // && means 'and' and || means 'or'
        {
            if (angles.y < 35)
            {
                todo.text = "Move head slightly more to right";
            }
            else if (angles.y > 65)
            {
                todo.text = "Move head slightly back to left";
            }
        }

//  *** Step 2 Walkthrough ***

        if ((timer == duration) && (flag1) && (!range2) && (!range3) && (!range4) && ((angles.x > 275) && (angles.x < 285)))
        {
            todo.text = "Tilt head to the right";
        }

        if ((flag1) && (!flag2) && ((angles.x > 295 && angles.x < 360) || (angles.x > 0 && angles.x < 20)) && ((angles.y > 80) && (angles.y < 140)))
        {
            range2    = true;
            timer    -= Time.deltaTime;
            inttime   = (int)timer;
            time.text = inttime.ToString();
            step.text = stepnum.ToString();
            todo.text = "Hold for " + duration + " seconds";

            if (inttime == 0)
            {
                canvas2.SetActive(false);
                if (video2.isPlaying)
                {
                    video2.Stop();
                }
                video3.Play();

                flag2     = true;
                todo.text = "Step 2 complete. Move the head anti-cw by 90 degrees";
                stepnum++;
                timer     = duration;
                inttime   = duration;
                time.text = inttime.ToString();
                step.text = stepnum.ToString();
            }
        }

        if ((timer != duration) && (flag1) && (!range3) && (!range4) && (((angles.x > 275) && (angles.x < 295)) || ((angles.x > 20) && (angles.x < 40)) || ((angles.y < 80) || (angles.y > 140))))
        {
            if ((angles.x > 275) && (angles.x < 295))
            {
                todo.text = "Tilt head slightly more to the right";
            }
            else if ((angles.x > 20) && (angles.x < 40))
            {
                todo.text = "Tilt head slightly back to left";
            }

            if ((angles.y < 80) && ((angles.x > 295 && angles.x < 360) || (angles.x > 0 && angles.x < 20)))
            {
                todo.text = "Move head slightly down";
            }
            else if ((angles.y > 140) && ((angles.x > 295 && angles.x < 360) || (angles.x > 0 && angles.x < 20)))
            {
                todo.text = "Move head slightly up";
            }
        }

// *** Step 3 Walkthrough ***

        if ((timer == duration) && (flag2) && (!range3) && (!range4) && (angles.x > 285) && (angles.y > (190)) && (angles.y < 220))
        {
            todo.text = "Tilt head more to the left";
        }
        if ((timer == duration) && (flag2) && (!range3) && (!range4) && (angles.x < 285) && (angles.y > (220)))
        {
            todo.text = "Lower head slightly";
        }

        if ((flag2) && (!flag3) && ((angles.x > 285) && (angles.x < 330)) && ((angles.y > 220) && (angles.y < 260)))
        {
            range3 = true;

            timer    -= Time.deltaTime;
            inttime   = (int)timer;
            time.text = inttime.ToString();
            step.text = stepnum.ToString();
            todo.text = "Hold for " + duration + " seconds";

            if (inttime == 0)
            {
                canvas3.SetActive(false);
                if (video3.isPlaying)
                {
                    video3.Stop();
                }
                video4.Play();

                flag3 = true;

                todo.text = "Step 3 complete. Move head anti-cw by another 90 degrees";
                stepnum++;
                timer     = duration;
                inttime   = duration;
                time.text = inttime.ToString();
                step.text = stepnum.ToString();
            }
        }

        if ((flag1) && (flag2) && (!range4) && (timer != duration) && (((angles.x < 285) || (angles.x > 330)) || ((angles.y < 220) || (angles.y > 260))))
        {
            if (angles.x < 285)
            {
                todo.text = "Tilt head slightly more to left";
            }
            else if (angles.x > 330)
            {
                todo.text = "Tilt head slightly back to right";
            }

            if ((angles.y < 220) && ((angles.x > 285) && (angles.x < 330)))
            {
                todo.text = "Move head slightly up";
            }
            else if ((angles.y > 260) && ((angles.x > 285) && (angles.x < 330)))
            {
                todo.text = "Move head slightly down";
            }
            flag3 = false;
//					todo.text = "Third step incomplete";
        }

// *** Step 4 Walkthrough ***

        if ((timer == duration) && (flag3) && (!range4) && ((angles.x > 0) && (angles.x < 20)))
        {
            todo.text = "Tilt head more towards the ground";
        }

        if ((timer == duration) && (flag3) && (!range4) && ((angles.x > 40) && (angles.x < 70)))
        {
            todo.text = "Look up";
        }

        if ((flag3) && (!flag4) && ((angles.z > 25) && (angles.z < 70)) && ((angles.x > 10) && (angles.x < 40)))
        {
            range4 = true;

            timer    -= Time.deltaTime;
            inttime   = (int)timer;
            time.text = inttime.ToString();
            step.text = stepnum.ToString();
            todo.text = "Hold for " + duration + " seconds";
            if (inttime == 0)
            {
                player3.SetActive(false);
                if (video3.isPlaying)
                {
                    video3.Stop();
                }
                video4.Play();

                flag4     = true;
                todo.text = "Step 4 complete. Rise up vertically";
                stepnum++;
                timer     = duration;
                inttime   = duration;
                time.text = inttime.ToString();
                step.text = stepnum.ToString();
            }
        }

        if ((flag1) && (flag2) && (flag3) && (range4) && (timer != duration) && (((angles.z < 25) || (angles.z > 70)) || ((angles.x < 10) || (angles.x > 40))))
        {
            if (angles.x < 10)
            {
                todo.text = "Tilt head slightly towards the ground";
            }
            else if (angles.x > 40)
            {
                todo.text = "Tilt head back in opposite direction";
            }

            if ((angles.z < 25) && ((angles.y > 220) && (angles.y < 260)))
            {
                todo.text = "Move head slightly downwards";
            }
            else if ((angles.z > 70) && ((angles.y > 220) && (angles.y < 260)))
            {
                todo.text = "Move head slightly upwards";
            }
            flag4 = false;
//					todo.text = "Fourth step incomplete";
        }


// *** Completion message ***

        if ((flag1) && (flag2) && (flag3) && (flag4) && ((angles.z > 0) && (angles.z < 10)) && (angles.x < 10 || angles.x > 340))
        {
            todo.text = "Epley's Maneuver Complete";
            timer     = duration;
            inttime   = duration;
            flag5     = true;
        }

        if ((flag1) && (flag2) && (flag3) && (flag4) && (flag5))           // Flags for completion of each step
        {
            hasEnd = true;
        }

        if (hasEnd)
        {
            pause += Time.deltaTime;              // A pause of four seconds added after Maneuver ends
            if (pause >= 4)
            {
                SceneManager.LoadScene("end");
            }
        }
    }