Exemple #1
0
    //Called by VR Rig
    public ObjectState TryGoal()
    {
        RaycastHit hit;

        // Bit mask for layer filtering
        LayerMask lm = 1 << 12;

        //Collision detection with colliders
        Goal g = GetGoal();

        if (g != null)
        {
            if (g.id == this.id)
            {
                g.willHighlightAfterObjectReached = true;
                currentGoal = g;
                if (currentGoal.descriptionFR != null)
                {
                    am.PlayObjectDescription(currentGoal.descriptionFR);
                }
                onSucceeded.Invoke();
                am.PlayCorrectSound();
                sm.EvaluateStreak();
                if (currentGoal.GetComponent <SpriteRenderer>() != null)
                {
                    currentGoal.Completed = true;
                    currentGoal.Animating = true;
                }
            }
            else
            {
                am.PlayDefeatSound();
                sm.AddMistake();
            }
        }
        //Detection by raycast

        /* old
         * else if (Physics.Raycast(this.transform.position, Vector3.left, out hit, lm)) {
         *  if (hit.distance < rayCastDistance) {
         *      Goal rayg = hit.transform.GetComponent<Goal>();
         *      if (rayg != null) {
         *          if (rayg.id == this.id && gm.showCasingObject == false) {
         *              currentGoal = rayg;
         *              Succeed();
         *             // Destroy(this.gameObject); //demo purpose
         *              return ObjectState.OnGoodGoal;
         *          } else {
         *              Fail();
         *              return ObjectState.OnBadGoal;
         *          }
         *      }
         *  }
         * }
         * return ObjectState.NotOnGoal;
         */
        /* new */
        else if (currentHand != null && Physics.Raycast(this.transform.position, currentHand.transform.forward, out hit, lm))
        {
            if (hit.distance < rayCastDistance)
            {
                Goal rayg = hit.transform.GetComponent <Goal>();
                if (rayg != null)
                {
                    if (rayg.id == this.id && gm.showCasingObject == false)
                    {
                        currentGoal = rayg;
                        Succeed();
                        // Destroy(this.gameObject); //demo purpose
                        return(ObjectState.OnGoodGoal);
                    }
                    else
                    {
                        Fail();
                        return(ObjectState.OnBadGoal);
                    }
                }
            }
        }
        return(ObjectState.NotOnGoal);
    }