Example #1
0
    public void Update()
    {
        //Debug.DrawRay(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector3.forward * 10f, Color.red);
        if (_CurrentScene == "Level")
        {
            float time = Time.time;
            sessionActive = (Time.time - sessionTimeStart < sessionLength * 60);

            if (input.TouchActive)
            {
                //Debug.Log("touchInput: [" + mainCam.WorldToViewportPoint(input.TouchPos) + "]");
                HitType hitType = activeLevel.AttemptHit(input.TouchPos);

                if (hitType == HitType.TargetHit || hitType == HitType.TargetHitLevelComplete || hitType == HitType.WrongTargetHit)
                {
                    if (sessionActive)
                    {
                        // We don't measure reaction time for the first hit because it is affected
                        // by the animation time and is hardly comparable to other times.
                        float reactionTime = -1.0f;
                        if (lastHitTime > -1.0f)
                        {
                            reactionTime = Time.time - lastHitTime;
                        }

                        // We don't measure distance of the first hit because
                        // there is no sensible start position we can measure from.
                        Vector2 hitPos   = mainCam.WorldToViewportPoint(input.TouchPos);
                        float   distance = -1.0f;

                        if (lastHitPos.x > -1.0f && lastHitPos.y > -1.0f)
                        {
                            distance = Vector2.Distance(lastHitPos, hitPos);
                        }

                        levelHitsTotal += 1;

                        dataManager.AddHit(hitPos, reactionTime, distance, hitType, activeLevelAssistance.GetAssistanceWasActive());
                        activeLevelAssistance.resetAssistanceWasActive();

                        lastHitTime = Time.time;
                        lastHitPos  = hitPos;
                    }

                    if (hitType == HitType.TargetHitLevelComplete)
                    {
                        TheLevelEnded();
                    }
                    Debug.Log("sessionActive: " + sessionActive + " sessionTime(" + (Time.time - sessionTimeStart) + ") lastHitPos[" + lastHitPos.x + lastHitPos.y +
                              ") LastHitTime( " + lastHitTime + ")");
                }
            }
            else if (input.TouchUp)
            {
                activeLevel.TempHit = null;
            }
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            GameObject.Find("GameLevel").GetComponent <GameLevel>().ReloadLevel();
        }
    }