public void TriggerUp(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
 {
     if (Trigger_Last_State == true)
     {
         Trigger_Last_State = false;
         Trigger_Marker.Write("Trigger Released");
     }
 }
    // Called if something collides with this object
    public void OnCollisionEnter(Collision collision)
    {
        string[] mark = new string[2];

        if (!collided)
        {
            // color change to make it clear when user collides
            Color cp_color = collision_panel.color;
            cp_color.a           += 0.5f;
            collision_panel.color = cp_color;

            // Logs time of collision and updates points
            c_control.event_log.Add(collision.gameObject.name + " collided with " + gameObject.name);
            c_control.event_log.Add(Time.time.ToString());
            point_counter.Update_Points(-100);
            collided = true;

            // Send type of collision to LSL for synchronization
            if (gameObject.name == "A1_Collider")
            {
                mark[0] = "-51";
                mark[1] = (Time.time).ToString();
                markerStream.Write(mark);
            }
            else if (gameObject.name == "A2_Collider")
            {
                mark[0] = "-52";
                mark[1] = (Time.time).ToString();
                markerStream.Write(mark);
            }
            else if (gameObject.name == "A3_Collider")
            {
                mark[0] = "-53";
                mark[1] = (Time.time).ToString();
                markerStream.Write(mark);
            }
            else                                        // Collision with the ISS
            {
                mark[0] = "-55";
                mark[1] = (Time.time).ToString();
                markerStream.Write(mark);
            }
        }
    }
 IEnumerator WriteContinouslyMarkerEachSecond()
 {
     while (true)
     {
         // an example for demonstrating the usage of marker stream
         var currentMarker = GetARandomMarker();
         markerStream.Write(currentMarker);
         yield return(new WaitForSecondsRealtime(1f));
     }
 }
Esempio n. 4
0
 //Sending marker
 void sendMarker()
 {
     if (!eventMarkerRun)
     {
         print(CurrentStatus);
         marker.Write(CurrentStatus);
         eventMarkerRun = true;
     }
     //eventMarkerRun = true;
 }
Esempio n. 5
0
    /* Single Flash Operation */
    IEnumerator SingleFlash()
    {
        while (startFlashes)
        {
            //Generate a random number from the list of indices that have non-zero counters
            System.Random random           = new System.Random();
            int           randomIndex      = random.Next(s_indexes.Count);
            int           randomShapeIndex = s_indexes[randomIndex];

            //Turn off the cubes to give the flashing image
            TurnOff();

            //If the counter is non-zero, then flash that cube and decrement the flash counter
            if (flash_counter[randomShapeIndex] > 0)
            {
                yield return(new WaitForSecondsRealtime((1f / freqHz)));

                Shapes2D.Shape randomShape = arcShapes[randomIndex];
                randomShape.settings.fillColor = onColor;
                flash_counter[randomShapeIndex]--;
                counter++;
                //print("CUBE: " + randomShape.ToString());
                //print(counter);

                //Write to the LSL Outlet stream
                marker.Write("s," + randomShape.ToString());
            }
            else if (numTrials == counter)
            {
                print("Done P300 Single Flash Trials");
                break;
            }
            else
            {
                //If the counter for a specific cube has reached zero, then remove it from the indexes so that the random
                //number generator does not pick it again (to reduce lag)
                if (flash_counter[randomShapeIndex] == 0)
                {
                    s_indexes.RemoveAt(randomIndex);
                }
                //Go to the next iteration of the single flash
                continue;
            }

            yield return(new WaitForSecondsRealtime(flashLength));
        }
        ResetCounters();
        //Write to LSL stream to indicate end of P300 SingleFlash
        //marker.Write("P300 SingleFlash Ends");
        startFlashes = !startFlashes;
        //keyLocks[KeyCode.S] = !keyLocks[KeyCode.S];
    }
    void Start()
    {
        startTime = Time.time;

        ee_target        = latching_EE_target.GetComponent <EE_target>();
        initial_rotation = all_joints[0].transform.rotation;

        // Get initial (1D) angles of each robotic joint
        angles[0] = all_joints[0].transform.localEulerAngles[2];
        angles[1] = all_joints[1].transform.localEulerAngles[2];
        angles[2] = all_joints[2].transform.localEulerAngles[1];
        angles[3] = all_joints[3].transform.localEulerAngles[1];
        angles[4] = all_joints[4].transform.localEulerAngles[1];
        angles[5] = all_joints[5].transform.localEulerAngles[2];
        angles[6] = all_joints[6].transform.localEulerAngles[2];

        // Cleans each angle to be between -180 and 180 degrees, then converts to radians
        for (int i = 0; i < angles.Length; i++)
        {
            if (angles[i] > 180)
            {
                angles[i] -= 360;
            }
            angles[i] = angles[i] * Mathf.PI / 180.0f;
        }

        // Initializes kinematics
        kinematics.initialize_FK();
        //kinematics.forward_kinematics(angles);  // Used for debugging
        kinematics.build_canadarm_jacobian(angles);

        // Initializes LSL stream - the python code will read this in to begin recording EEG data
        if (record_EEG)
        {
            mark[0] = "100";
            mark[1] = (Time.time).ToString();
            markerStream.Write(mark);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (!listener.Pending())
        {
            marker.Write("start of data rec " + this.name);                     // perhaps write at the point of eeg? test
        }
        else
        {
            print("socket comes");
            TcpClient     client = listener.AcceptTcpClient();
            NetworkStream ns     = client.GetStream();
            StreamReader  reader = new StreamReader(ns);
            msg = reader.ReadToEnd();
            print(msg);
            FadeToBlack();


            // UnityEditor.EditorApplication.isPlaying = false;
            marker.Write("end of data rec ");
            t.Update();
            time_end = t.UpdateTimeStamp;
            print(time_end);
        }
    }
Esempio n. 8
0
 public void Send(int marker)
 {
     if (!(preventConsecutiveIdenticalMarkers && marker == lastMarker))
     {
         if (markerSentThisFrame)
         {
             // A marker was already sent this frame, queue it for the next frame
             markerQueue.Add(marker);
         }
         else
         {
             // No marker has been sent this frame, so just send it now
             markerStream.Write(marker);
             Debug.Log("Sending marker " + marker);
             markerSentThisFrame = true;
         }
         lastMarker = marker;
     }
 }
    private void OnTriggerStay(Collider other)
    {
        string[] mark = new string[2];
        if (other.gameObject.name == "Grapple_Fixture_Collider")
        {
            if (!connected_to_rm)
            {
                if (Input.GetKeyDown("joystick button 1"))  // If user presses the "x" button
                {
                    Hamlyn_Module.transform.parent = transform;
                    print("Hamlyn Module engaged");
                    print(Time.time);
                    print(System.DateTime.Now);

                    canadarm_control.event_log.Add("Hamlyn Module engaged");
                    canadarm_control.event_log.Add(Time.time.ToString());
                    canadarm_control.event_log.Add(System.DateTime.Now.ToString());

                    if (three_panel)
                    {
                        canadarm_control.cameras[3] = columbus_camera.gameObject;
                        columbus_camera.depth       = 2;
                    }

                    Vector3    grap_fixt_pos    = other.transform.position;
                    Quaternion grap_fixt_orient = other.transform.rotation;
                    Vector3    this_pos         = transform.position;
                    Quaternion this_orient      = transform.rotation;

                    float dist_between  = Vector3.Distance(grap_fixt_pos, this_pos);
                    float angle_between = Quaternion.Angle(grap_fixt_orient, this_orient);

                    int points_change_dist  = Mathf.RoundToInt(100.0f / dist_between);
                    int points_change_angle = Mathf.RoundToInt(5000.0f / angle_between);
                    int total_points_change = points_change_dist + points_change_angle;

                    print("Distance:");
                    print(dist_between);
                    print(points_change_dist);
                    print("Angle:");
                    print(angle_between);
                    print(points_change_angle);

                    canadarm_control.event_log.Add("Distance:");
                    canadarm_control.event_log.Add(dist_between.ToString("f3"));
                    canadarm_control.event_log.Add(points_change_dist.ToString());
                    canadarm_control.event_log.Add("Angle:");
                    canadarm_control.event_log.Add(angle_between.ToString("f2"));
                    canadarm_control.event_log.Add(points_change_angle.ToString());

                    point_counter.Update_Points(total_points_change);
                    // Send to LSL
                    mark[0] = "1000";
                    mark[1] = total_points_change.ToString();

                    markerStream.Write(mark);
                    //print("Columbus_attachpoint - xpoint pressed -- LSL sent");

                    //markerStream.Write(total_points_change.ToString());

                    connected_to_rm = true;
                }
            }
        }

        if (other.gameObject.name == "Columbus_attachpoint")
        {
            //string[] mark = new string[2];
            if (Input.GetKeyDown("joystick button 3"))   // If user presses the "triangle" button
            {
                Hamlyn_Module.transform.parent = null;
                print("Hamlyn Module unloaded");
                print(Time.time);
                print(System.DateTime.Now);

                canadarm_control.event_log.Add("Hamlyn Module unloaded");
                canadarm_control.event_log.Add(Time.time.ToString());
                canadarm_control.event_log.Add(System.DateTime.Now.ToString());

                if (three_panel)
                {
                    canadarm_control.cameras[3] = EE_camera.gameObject;
                    columbus_camera.depth       = 0;
                }

                Vector3    grap_fixt_pos    = other.transform.position;
                Quaternion grap_fixt_orient = other.transform.rotation;
                Vector3    this_pos         = transform.position;
                Quaternion this_orient      = transform.rotation;

                float dist_between  = Vector3.Distance(grap_fixt_pos, this_pos);
                float angle_between = Quaternion.Angle(grap_fixt_orient, this_orient);

                int points_change_dist  = Mathf.RoundToInt(100.0f / dist_between);
                int points_change_angle = Mathf.RoundToInt(5000.0f / angle_between);
                int total_points_change = points_change_dist + points_change_angle;

                //print("Distance:");
                //print(dist_between);
                //print(points_change_dist);
                //print("Angle:");
                //print(angle_between);
                //print(points_change_angle);

                canadarm_control.event_log.Add("Distance:");
                canadarm_control.event_log.Add(dist_between.ToString("f3"));
                canadarm_control.event_log.Add(points_change_dist.ToString());
                canadarm_control.event_log.Add("Angle:");
                canadarm_control.event_log.Add(angle_between.ToString("f2"));
                canadarm_control.event_log.Add(points_change_angle.ToString());

                point_counter.Update_Points(total_points_change);
                // Send to LSL
                //markerStream.Write(total_points_change.ToString(), Time.time);
                mark[0] = "2000";
                mark[1] = total_points_change.ToString();

                markerStream.Write(mark);
                //print("Columbus_attachpoint - triangle pressed-- LSL sent");

                canadarm_control.Save_Data();
            }
        }
    }
Esempio n. 10
0
    // Update is called once per frame
    void Update()
    {
        //Row/Column Flash P300
        //Conditional to check key locks
        if (Input.GetKeyDown(KeyCode.R) && keyLocks[KeyCode.S] == false && keyLocks[KeyCode.D] == false && !locked_keys)
        {
            keyLocks[KeyCode.R] = !keyLocks[KeyCode.R];
            startFlashes        = !startFlashes;

            if (startFlashes)
            {
                print("Starting P300 RCFlash");
                marker.Write("P300 RCFlash Begins");
                SetUpRC();
                StartCoroutine("RCFlash");
            }
            else
            {
                // Selected if the user pauses the simulation before it is complete
                print("Stopping P300 RCFlash");
                marker.Write("P300 RCFlash Ends");
                StopCoroutine("RCFlash");
                ResetCounters();
                print("Counters Reset! Hit G again to run P300 RCFlash");
            }
        }

        //Single Flash P300
        //Conditional to check key locks
        if (Input.GetKeyDown(KeyCode.S) && keyLocks[KeyCode.R] == false && keyLocks[KeyCode.D] == false && !locked_keys)
        {
            keyLocks[KeyCode.S] = !keyLocks[KeyCode.S];
            startFlashes        = !startFlashes;

            if (startFlashes)
            {
                print("Starting P300 SingleFlash");
                //Writing to LSL to signal start of simulation
                marker.Write("P300 SingleFlash Begins");
                SetUpSingle();
                StartCoroutine("SingleFlash");
            }
            else
            {
                // Selected if the user pauses the simulation before it is complete
                print("Stopping P300 SingleFlash");
                //Writing to LSL to signal end of simulation
                marker.Write("P300 SingleFlash Ends");
                StopCoroutine("SingleFlash");
                ResetCounters();
                print("Counters Reset! Hit S again to run P300 SingleFlash");
            }
        }

        //Redraw Matrix
        //Select this after changing parameters
        if (Input.GetKeyDown(KeyCode.D) && keyLocks[KeyCode.R] == false && keyLocks[KeyCode.S] == false)
        {
            //Check if values are empty
            if (CheckEmpty())
            {
                print("Values must be non-zero and non-negative, please re-enter values and try again...");
                locked_keys = true;
                return;
            }
            keyLocks[KeyCode.D] = true;
            print("Redrawing Matrix");
            TurnOff();
            DestroyMatrix();
            ResetCounters();
            cube_list.Clear();
            SetUpMatrix();
            SetUpSingle();
            SetUpRC();
            TurnOff();
            keyLocks[KeyCode.D] = false;
            locked_keys         = false;
        }

        //Quit Program
        if (Input.GetKeyDown(KeyCode.Q))
        {
            print("Quitting Program...");
            marker.Write("Quit");
            marker = null;
            Application.Quit();
        }
    }
Esempio n. 11
0
    // Start is called before the first frame update
    void Start()
    {
        //Get the screen refresh rate, so that the colours can be set appropriately
        resol       = Screen.resolutions;
        refreshRate = resol[3].refreshRate;
        //Set up LSL Marker Stream
        marker = FindObjectOfType <LSLMarkerStream>();

        //Setting up Keys, to lock other keys when one simulation is being run
        keyLocks.Add(KeyCode.R, false);
        keyLocks.Add(KeyCode.S, false);
        //keyLocks.Add(KeyCode.D, false); //Removing Key 'D' since redraw matrix is meant for dynamically created matrices
        locked_keys = false;

        /* Speech Recognizer Variables */
        keywords.Add("Start Flash", () =>
        {
            //Copied code from SingleFlash
            keyLocks[KeyCode.S] = !keyLocks[KeyCode.S];
            startFlashes        = !startFlashes;

            if (startFlashes)
            {
                print("Starting P300 SingleFlash");
                //Writing to LSL to signal start of simulation
                marker.Write("P300 SingleFlash Begins");
                SetUpSingle();
                StartCoroutine("SingleFlash");
            }
            else
            {
                // Selected if the user pauses the simulation before it is complete
                print("Stopping P300 SingleFlash");
                //Writing to LSL to signal end of simulation
                marker.Write("P300 SingleFlash Ends");
                StopCoroutine("SingleFlash");
                ResetCounters();
                print("Counters Reset! Hit S again to run P300 SingleFlash");
            }
        });

        // Tell the KeywordRecognizer about our keywords
        keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray());

        //Register a callback for the KeywordRecognizer and start recognizing
        keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
        keywordRecognizer.Start();


        /* Unused Functionality, since cube matrix is not being created dynamically, there are no matrix reconfigurations to be made */
        //Check to see if inputs are valid, if not, then don't draw matrix and prompt user to redraw with the
        //correct inputs
        // if(CheckEmpty()){
        //     print("Values must be non-zero and non-negative, please re-enter values and press 'D' to redraw...");
        //     locked_keys = true;
        //     return;
        // }

        //Initialize Matrix
        HUD_Setup(); //Function specific to this program
                     //SetUpMatrix();
        SetUpSingle();
        SetUpRC();

        // SaveCurrentInfo();
        //Set the colour of the box to the given offColour
        TurnOff();
        System.Threading.Thread.Sleep(2000);
        SendInfo();

        /* Testing purposes */
        startFlashes        = !startFlashes;
        keyLocks[KeyCode.S] = !keyLocks[KeyCode.S];
        print("Starting P300 SingleFlash");
        marker.Write("P300 SingleFlash Begins");
        SetUpSingle();
        StartCoroutine("SingleFlash");
    }
Esempio n. 12
0
 virtual protected void writeMarker(string marker)
 {
     markerStream.Write(marker, LSL.liblsl.local_clock() + timeLSLRecordingOffset);
 }
Esempio n. 13
0
 void sendMarker()
 {
     Debug.Log("Writing marker " + (markerIndex + 1));
     markerIndex += 1;
     marker.Write("Marker " + markerIndex);
 }
Esempio n. 14
0
    // Update is called once per frame
    void Update()
    {
        if (m.isDark)
        {
            allAnswered       = false;
            answeredArousal   = false;
            answeredValence   = false;
            answeredDominance = false;
            selectionSquareArousal.SetActive(false);
            selectionSquareValence.SetActive(false);
            selectionSquareDominance.SetActive(false);
        }

        if (insideSquareScript.insideSquare && !m.isDark && m.circleTouched)
        {
            canAnswer = true;
        }
        else
        {
            canAnswer = false;
        }

        //The first questionnaire--Arousal
        if (canAnswer && !answeredArousal && !answeredValence && !answeredDominance)
        {
            //Setting Arousal on first
            Arousal.SetActive(true);

            if (Input.GetKeyDown("1"))
            {
                selectionSquareArousal.SetActive(true);
                if (Input.GetKeyDown("1") && selectionSquareArousal.transform.position == A0.transform.position)
                {
                    //Debug.Log(m.CurrentStatus + ";Arousal1");
                    m.eventMarkerRun = false;
                    sendMarker(";Arousal1");
                    StartCoroutine(Selected(A0));
                    StartCoroutine(Selected(selectionSquareArousal));
                    StartCoroutine(RemoveQuestionnaire(Arousal));
                }
                selectionSquareArousal.transform.position = A0.transform.position;
            }
            if (Input.GetKeyDown("2"))
            {
                selectionSquareArousal.SetActive(true);
                if (Input.GetKeyDown("2") && selectionSquareArousal.transform.position == A1.transform.position)
                {
                    //Debug.Log(m.CurrentStatus + ";Arousal2");
                    m.eventMarkerRun = false;
                    sendMarker(";Arousal2");
                    StartCoroutine(Selected(A1));
                    StartCoroutine(Selected(selectionSquareArousal));
                    StartCoroutine(RemoveQuestionnaire(Arousal));
                }
                selectionSquareArousal.transform.position = A1.transform.position;
            }
            if (Input.GetKeyDown("3"))
            {
                selectionSquareArousal.SetActive(true);
                if (Input.GetKeyDown("3") && selectionSquareArousal.transform.position == A2.transform.position)
                {
                    //Debug.Log(m.CurrentStatus + ";Arousal3");
                    m.eventMarkerRun = false;
                    sendMarker(";Arousal3");
                    StartCoroutine(Selected(A2));
                    StartCoroutine(Selected(selectionSquareArousal));
                    StartCoroutine(RemoveQuestionnaire(Arousal));
                }
                selectionSquareArousal.transform.position = A2.transform.position;
            }
            if (Input.GetKeyDown("4"))
            {
                selectionSquareArousal.SetActive(true);
                if (Input.GetKeyDown("4") && selectionSquareArousal.transform.position == A3.transform.position)
                {
                    //Debug.Log(m.CurrentStatus + ";Arousal4");
                    m.eventMarkerRun = false;
                    sendMarker(";Arousal4");
                    StartCoroutine(Selected(A3));
                    StartCoroutine(Selected(selectionSquareArousal));
                    StartCoroutine(RemoveQuestionnaire(Arousal));
                }
                selectionSquareArousal.transform.position = A3.transform.position;
            }
            if (Input.GetKeyDown("5"))
            {
                selectionSquareArousal.SetActive(true);
                if (Input.GetKeyDown("5") && selectionSquareArousal.transform.position == A4.transform.position)
                {
                    //Debug.Log(m.CurrentStatus + ";Arousal5");
                    m.eventMarkerRun = false;
                    sendMarker(";Arousal5");
                    StartCoroutine(Selected(A4));
                    StartCoroutine(Selected(selectionSquareArousal));
                    StartCoroutine(RemoveQuestionnaire(Arousal));
                }
                selectionSquareArousal.transform.position = A4.transform.position;
            }
        }

        //The second questionnaire--Valence
        if (canAnswer && answeredArousal && !answeredValence && !answeredDominance)
        {
            //Setting Valence on first
            Valence.SetActive(true);

            if (Input.GetKeyDown("1"))
            {
                selectionSquareValence.SetActive(true);
                if (Input.GetKeyDown("1") && selectionSquareValence.transform.position == V0.transform.position)
                {
                    //Debug.Log(m.CurrentStatus + ";Valence1");
                    m.eventMarkerRun = false;
                    sendMarker(";Valence1");
                    StartCoroutine(Selected(V0));
                    StartCoroutine(Selected(selectionSquareValence));
                    StartCoroutine(RemoveQuestionnaire(Valence));
                }
                selectionSquareValence.transform.position = V0.transform.position;
            }
            if (Input.GetKeyDown("2"))
            {
                selectionSquareValence.SetActive(true);
                if (Input.GetKeyDown("2") && selectionSquareValence.transform.position == V1.transform.position)
                {
                    //Debug.Log(m.CurrentStatus + ";Valence2");
                    m.eventMarkerRun = false;
                    sendMarker(";Valence2");
                    StartCoroutine(Selected(V1));
                    StartCoroutine(Selected(selectionSquareValence));
                    StartCoroutine(RemoveQuestionnaire(Valence));
                }
                selectionSquareValence.transform.position = V1.transform.position;
            }
            if (Input.GetKeyDown("3"))
            {
                selectionSquareValence.SetActive(true);
                if (Input.GetKeyDown("3") && selectionSquareValence.transform.position == V2.transform.position)
                {
                    //Debug.Log(m.CurrentStatus + ";Valence3");
                    m.eventMarkerRun = false;
                    sendMarker(";Valence3");
                    StartCoroutine(Selected(V2));
                    StartCoroutine(Selected(selectionSquareValence));
                    StartCoroutine(RemoveQuestionnaire(Valence));
                }
                selectionSquareValence.transform.position = V2.transform.position;
            }
            if (Input.GetKeyDown("4"))
            {
                selectionSquareValence.SetActive(true);
                if (Input.GetKeyDown("4") && selectionSquareValence.transform.position == V3.transform.position)
                {
                    //Debug.Log(m.CurrentStatus + ";Valence4");
                    m.eventMarkerRun = false;
                    sendMarker(";Valence4");
                    StartCoroutine(Selected(V3));
                    StartCoroutine(Selected(selectionSquareValence));
                    StartCoroutine(RemoveQuestionnaire(Valence));
                }
                selectionSquareValence.transform.position = V3.transform.position;
            }
            if (Input.GetKeyDown("5"))
            {
                selectionSquareValence.SetActive(true);
                if (Input.GetKeyDown("5") && selectionSquareValence.transform.position == V4.transform.position)
                {
                    //Debug.Log(m.CurrentStatus + ";Valence5");
                    m.eventMarkerRun = false;
                    sendMarker(";Valence5");
                    StartCoroutine(Selected(V4));
                    StartCoroutine(Selected(selectionSquareValence));
                    StartCoroutine(RemoveQuestionnaire(Valence));
                }
                selectionSquareValence.transform.position = V4.transform.position;
            }
        }

        //The third questionnaire--Dominance
        if (canAnswer && answeredArousal && answeredValence && !answeredDominance)
        {
            //Setting Dominance on
            Dominance.SetActive(true);

            if (Input.GetKeyDown("1"))
            {
                selectionSquareDominance.SetActive(true);
                if (Input.GetKeyDown("1") && selectionSquareDominance.transform.position == D0.transform.position)
                {
                    //Debug.Log(m.CurrentStatus + ";Dominance1");
                    m.eventMarkerRun = false;
                    sendMarker(";Dominance1");
                    StartCoroutine(Selected(D0));
                    StartCoroutine(Selected(selectionSquareDominance));
                    StartCoroutine(RemoveQuestionnaire(Dominance));
                }
                selectionSquareDominance.transform.position = D0.transform.position;
            }
            if (Input.GetKeyDown("2"))
            {
                selectionSquareDominance.SetActive(true);
                if (Input.GetKeyDown("2") && selectionSquareDominance.transform.position == D1.transform.position)
                {
                    //Debug.Log("#" + m.CurrentTrial.ToString() + "Dominance2");
                    m.eventMarkerRun = false;
                    sendMarker(";Dominance2");
                    StartCoroutine(Selected(D1));
                    StartCoroutine(Selected(selectionSquareDominance));
                    StartCoroutine(RemoveQuestionnaire(Dominance));
                }
                selectionSquareDominance.transform.position = D1.transform.position;
            }
            if (Input.GetKeyDown("3"))
            {
                selectionSquareDominance.SetActive(true);
                if (Input.GetKeyDown("3") && selectionSquareDominance.transform.position == D2.transform.position)
                {
                    //Debug.Log("#" + m.CurrentTrial.ToString() + "Dominance3");
                    m.eventMarkerRun = false;
                    sendMarker(";Dominance3");
                    StartCoroutine(Selected(D2));
                    StartCoroutine(Selected(selectionSquareDominance));
                    StartCoroutine(RemoveQuestionnaire(Dominance));
                }
                selectionSquareDominance.transform.position = D2.transform.position;
            }
            if (Input.GetKeyDown("4"))
            {
                selectionSquareDominance.SetActive(true);
                if (Input.GetKeyDown("4") && selectionSquareDominance.transform.position == D3.transform.position)
                {
                    //Debug.Log("#" + m.CurrentTrial.ToString() + "Dominance4");
                    m.eventMarkerRun = false;
                    sendMarker(";Dominance4");
                    StartCoroutine(Selected(D3));
                    StartCoroutine(Selected(selectionSquareDominance));
                    StartCoroutine(RemoveQuestionnaire(Dominance));
                }
                selectionSquareDominance.transform.position = D3.transform.position;
            }
            if (Input.GetKeyDown("5"))
            {
                selectionSquareDominance.SetActive(true);
                if (Input.GetKeyDown("5") && selectionSquareDominance.transform.position == D4.transform.position)
                {
                    //Debug.Log("#" + m.CurrentTrial.ToString() + "Dominance5");
                    m.eventMarkerRun = false;
                    sendMarker(";Dominance5");
                    StartCoroutine(Selected(D4));
                    StartCoroutine(Selected(selectionSquareDominance));
                    StartCoroutine(RemoveQuestionnaire(Dominance));
                }
                selectionSquareDominance.transform.position = D4.transform.position;
            }
        }

        //Resetting the color of the selection square for next trial
        if (!canAnswer || (answeredArousal && answeredDominance && answeredValence))
        {
            StartCoroutine(ResettingColor(selectionSquareArousal, A0, A1, A2, A3, A4));
            StartCoroutine(ResettingColor(selectionSquareValence, V0, V1, V2, V3, V4));
            StartCoroutine(ResettingColor(selectionSquareDominance, D0, D1, D2, D3, D4));
        }

        if (answeredArousal && answeredDominance && answeredValence)
        {
            allAnswered = true;
        }
        else
        {
            allAnswered = false;
        }

        //Fading the color of the square
        IEnumerator Selected(GameObject SAM)
        {
            for (float f = 1f; f > -0.05; f -= 0.01f)
            {
                selectedColor.a = f;
                SAM.GetComponent <SpriteRenderer>().color = selectedColor;
                yield return(new WaitForSeconds(0.01f));
            }
        }

        //Resetting the color for next trials
        IEnumerator ResettingColor(GameObject sq, GameObject one, GameObject two, GameObject three, GameObject four, GameObject five)
        {
            sq.GetComponent <SpriteRenderer>().color    = new Color(1, 1, 1, 1);
            one.GetComponent <SpriteRenderer>().color   = new Color(1, 1, 1, 1);
            two.GetComponent <SpriteRenderer>().color   = new Color(1, 1, 1, 1);
            three.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 1);
            four.GetComponent <SpriteRenderer>().color  = new Color(1, 1, 1, 1);
            five.GetComponent <SpriteRenderer>().color  = new Color(1, 1, 1, 1);
            yield return(null);
        }

        //Removing a questionnaire
        IEnumerator RemoveQuestionnaire(GameObject q)
        {
            yield return(new WaitForSeconds(1f));

            if (q.name == "SAM_Arousal")
            {
                answeredArousal = true;
            }
            if (q.name == "SAM_Valence")
            {
                answeredValence = true;
            }
            if (q.name == "SAM_Dominance")
            {
                answeredDominance = true;
            }
            q.SetActive(false);
        }

        void sendMarker(string SAM)
        {
            if (!m.eventMarkerRun)
            {
                print(m.CurrentStatus + SAM);
                sM.Write(m.CurrentStatus + SAM);
                m.eventMarkerRun = true;
            }
        }
    }