예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (this.appear_on_question == this.my_piece_manager.current_question && StartScene)
        {
            my_distance         = Vector3.Distance(this.target.position, this.transform.position);
            distance_from_start = Vector3.Distance(this.start_position.position, this.transform.position);
            Transform child = load_bar.transform;

            //move piece to start position:
            if (!this.is_on_start_position)
            {
                float step = (speed + 4f) * Time.deltaTime;
                this.transform.position = Vector3.MoveTowards(this.transform.position, this.start_position.position, step);
                if (this.distance_from_start <= 0.1f)
                {
                    this.is_activated         = true;
                    this.is_on_start_position = true;
                }
                else
                {
                    this.is_activated = false;
                }
            }

            /**/
            //Handle bar behaviour:
            if (this.gazed_at && this.is_bar_active)
            {
                timer += Time.deltaTime;
                //load_bar.SetActive (true);

                Vector3 newScale    = new Vector3((timer + 1) / gaze_time, child.localScale.y, child.localScale.z);
                Vector3 newPosition = new Vector3((timer / gaze_time) / 2, child.localPosition.y, child.localPosition.z);

                child.localScale    = newScale;
                child.localPosition = newPosition;
                if (timer >= gaze_time)
                {
                    //ExecuteEvents.Execute(gameObject, new PointerEventData(EventSystem.current), ExecuteEvents.pointerDownHandler);
                    this.startMovement();
                    timer = 0f;
                }
            }
            else
            {
                timer = 0f;
                load_bar.SetActive(false);
            }
            /**/

            //Move piece to board:
            if (this.is_moving)
            {
                float step = speed * Time.deltaTime;
                this.transform.position = Vector3.MoveTowards(this.transform.position, this.target.position, step);

                this.x_angle           += Time.deltaTime * this.rotate_speed;
                this.transform.rotation = Quaternion.Euler(-this.x_angle, 0, 0);

                //Reached location at board:
                if (this.my_distance <= 0.1f)
                {
                    this.is_on_goal         = true;
                    this.is_activated       = false;
                    this.transform.rotation = Quaternion.Euler(-90, 0, 0);
                    this.meshR.material     = final;
                    //Debug.Log ("LLegué a mi destino");

                    if (this.call_activate_others_once)
                    {
                        this.activateOthersOnce();
                    }
                    if (this.is_correct)
                    {
                        //Trigger correct answer sequence.
                        if (this.is_final)
                        {
                            AudioM.is_Final();
                        }
                        //play audio
                        AudioM.PlayAudio(1, this.Audio);
                        iMan.ChangeImagesSingleSelect(history);
                        //display image.
                        //when audio ends:
                        this.my_piece_manager.activateAll();
                        this.my_piece_manager.changeQuestion();

                        //New question and set of pieces appears
                    }
                    else
                    {
                        //Trigger incorrect answer sequence.
                        AudioM.PlayAudio(2, this.Audio);
                        iMan.ChangeImagesSingleSelect(history);
                        //play audio
                        //display image
                        //when audio ends:
                        this.my_piece_manager.activateAll();
                        this.is_bar_active = true;

                        Destroy(this.gameObject);
                    }

                    this.is_moving = false;
                }
            }
        }
        else if ((this.my_piece_manager.current_question > this.appear_on_question) &&
                 !this.is_correct)
        {
            Destroy(this.gameObject);
        }
    }    //END UPDATE.