void Update()
 {
     if (yessplus == true)
     {
         sub.transform.parent        = all_targets[detectedImageCount].transform;
         sub.transform.localPosition = new Vector3(0, -0.3f, 4);
         sub.transform.localRotation = Quaternion.Euler(90, 0, 0);
         yessplus = false;
     }
     if (yess == true)
     {
         oldFocusedObject = FocusedObject;
         oldDirection     = newDirection;
         oldPosition      = newPosition;
         sub.GetComponent <TextMesh>().text = (Camera.main.transform.position - difference).ToString() + '\n' + Camera.main.transform.up + '\n' + Camera.main.transform.forward;
         if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hitInfo))
         {
             FocusedObject = hitInfo.collider.gameObject;
             if (FocusedObject != oldFocusedObject)
             {
                 focusedobjectName = FocusedObject.name;
                 print(FocusedObject.name);
             }
         }
         else
         {
             FocusedObject     = null;
             focusedobjectName = "none";
         }
         newPosition  = Camera.main.transform.position - difference;
         newDirection = Camera.main.transform.forward;
         if (newPosition != oldPosition)
         {
             writer.WriteLine(focusedobjectName + "," + newPosition.ToString() + "," + Camera.main.transform.position + "," + difference + "," + Camera.main.transform.forward + ',' + Camera.main.transform.up + ',' + Time.time);
         }
         if (newDirection != oldDirection)
         {
             writer.WriteLine(focusedobjectName + "," + newPosition.ToString() + "," + Camera.main.transform.position + "," + difference + "," + Camera.main.transform.forward + ',' + Camera.main.transform.up + ',' + Time.time);
         }
     }
     if (update == true)
     {
         CheckUI();
         update = false;
     }
     if (Input.GetKeyDown("m"))
     {
         Subspaces.merge_spaces();
     }
     if (Input.GetKeyDown("1"))
     {
         writer.WriteLine("TRIAL 1");
         ModelInstantiator.hideAll();
         for (int i = 0; i < AllbatchCounts[0]; i++)
         {
             allHabitats[i].SetActive(true);
             LayeredHabitats[i].SetActive(true);
         }
         activeData = 1;
         LayeredMapping.hideOthers(0);
         ENVmds.hideScatter();
     }
     if (Input.GetKeyDown("2"))
     {
         writer.WriteLine("TRIAL 2");
         ModelInstantiator.hideAll();
         for (int i = AllbatchCounts[0]; i < AllbatchCounts[1]; i++)
         {
             allHabitats[i].SetActive(true);
             LayeredHabitats[i].SetActive(true);
         }
         activeData = 2;
         LayeredMapping.hideOthers(0);
         ENVmds.hideScatter();
     }
     if (Input.GetKeyDown("3"))
     {
         writer.WriteLine("TRIAL 3");
         ModelInstantiator.hideAll();
         for (int i = AllbatchCounts[1]; i < AllbatchCounts[2]; i++)
         {
             allHabitats[i].SetActive(true);
             LayeredHabitats[i].SetActive(true);
         }
         activeData = 3;
         LayeredMapping.hideOthers(0);
         ENVmds.hideScatter();
     }
     if (Input.GetKeyDown("4"))
     {
         writer.WriteLine("TRIAL 4");
         ModelInstantiator.hideAll();
         for (int i = AllbatchCounts[2]; i < AllbatchCounts[3]; i++)
         {
             allHabitats[i].SetActive(true);
             LayeredHabitats[i].SetActive(true);
         }
         activeData = 4;
         LayeredMapping.hideOthers(3);
         ENVmds.hideScatter();
     }
     if (Input.GetKeyDown("5"))
     {
         writer.WriteLine("TRIAL 5");
         ModelInstantiator.hideAll();
         for (int i = AllbatchCounts[3]; i < AllbatchCounts[4]; i++)
         {
             allHabitats[i].SetActive(true);
             LayeredHabitats[i].SetActive(true);
         }
         activeData = 5;
         LayeredMapping.hideOthers(6);
         ENVmds.hideScatter();
     }
     if (Input.GetKeyDown("6"))
     {
         writer.WriteLine("TRIAL 6");
         ModelInstantiator.hideAll();
         for (int i = AllbatchCounts[4]; i < AllbatchCounts[5]; i++)
         {
             allHabitats[i].SetActive(true);
             LayeredHabitats[i].SetActive(true);
         }
         activeData = 6;
         LayeredMapping.hideOthers(10);
         ENVmds.hideScatter();
     }
     if (Input.GetKeyDown("7"))
     {
         writer.WriteLine("TRIAL 7");
         LayeredMapping.hideOthers(0);
         ENVmds.hideScatter();
         ENVmds.read1();
     }
     if (Input.GetKeyDown("8"))
     {
         writer.WriteLine("TRIAL 8");
         LayeredMapping.hideOthers(0);
         ENVmds.hideScatter();
         ENVmds.read2();
     }
     if (Input.GetKeyDown("9"))
     {
         writer.WriteLine("TRIAL 9");
         LayeredMapping.hideOthers(0);
         ENVmds.hideScatter();
         ENVmds.read3();
     }
     if (Input.GetKeyDown("0"))
     {
         writer.WriteLine("TRIAL 10");
         DeleteAllENV();
         LayeredMapping.hideOthers(0);
         ENVmds.hideScatter();
         makeENVlayer(1);
         makeENVlayer(0);
         makeENVlayer(3);
     }
     if (Input.GetKeyDown("-"))
     {
         writer.WriteLine("TRIAL 11");
         DeleteAllENV();
         LayeredMapping.hideOthers(0);
         ENVmds.hideScatter();
         makeENVlayer(4);
         makeENVlayer(5);
         makeENVlayer(6);
         makeENVlayer(7);
         makeENVlayer(10);
         makeENVlayer(2);
     }
     if (Input.GetKeyDown("="))
     {
         writer.WriteLine("TRIAL 12");
         DeleteAllENV();
         LayeredMapping.hideOthers(0);
         ENVmds.hideScatter();
         makeENVlayer(10);
         makeENVlayer(9);
         makeENVlayer(8);
         makeENVlayer(15);
         makeENVlayer(17);
         makeENVlayer(20);
         makeENVlayer(21);
         makeENVlayer(11);
         makeENVlayer(22);
         makeENVlayer(23);
     }
     if (Input.GetKeyDown("b"))
     {
         ParallelCoordInstantiator.delete();
     }
     if (Input.GetKeyDown("z"))
     {
         //Subspaces.Highlight();
         //initHistory();
         //for (int i = 0; i < allHabitats.Count; i++)
         //{
         //    allHabitats[i].SetActive(true);
         //    //LayeredHabitats[i].SetActive(true);
         //}
     }
 }
    void Update()
    {
        if (Input.GetKeyDown("l"))
        {
            sub.GetComponent <TextMesh>().color = Color.green;
            difference = Camera.main.transform.position;
            yessplus   = true;
        }
        if (yessplus == true)
        {
            sub.transform.parent        = all_targets[detectedImageCount].transform;
            sub.transform.localPosition = new Vector3(0, -0.3f, 2);
            sub.transform.localRotation = Quaternion.Euler(90, 0, 0);
            yessplus       = false;
            subspaceWeight = true;
        }
        if (yess == true)
        {
            oldFocusedObject = FocusedObject;
            oldDirection     = newDirection;
            oldPosition      = newPosition;
            //sub.GetComponent<TextMesh>().text = (Camera.main.transform.position - difference).ToString();
            sub.GetComponent <TextMesh>().text = (Camera.main.transform.position - difference).ToString() + '\n' + Camera.main.transform.forward;
            if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hitInfo))
            {
                FocusedObject = hitInfo.collider.gameObject;
                if (FocusedObject != oldFocusedObject)
                {
                    focusedobjectName = FocusedObject.name;
                    //print(FocusedObject.name);
                }
            }
            else
            {
                FocusedObject     = null;
                focusedobjectName = "none";
            }
            newPosition  = Camera.main.transform.position - difference;
            newDirection = Camera.main.transform.forward;
            if (newPosition != oldPosition)
            {
                //writer.WriteLine(focusedobjectName + "," + newPosition.ToString() + "," + Camera.main.transform.position + "," + difference + "," + Camera.main.transform.forward + ',' + Time.time);
            }
            if (newDirection != oldDirection)
            {
                //writer.WriteLine(focusedobjectName + "," + newPosition.ToString() + "," + Camera.main.transform.position + "," + difference + "," + Camera.main.transform.forward + ',' + Time.time);
            }
        }
        if (update == true)
        {
            CheckUI();
            update = false;
        }

        if (Input.GetKeyDown("m"))
        {
            Subspaces.merge_spaces();
        }
        if (Input.GetKeyDown("1"))
        {
            ModelInstantiator.hideAll();
            //for (int i = 0; i < allHabitats.Count; i++)
            //{
            //    allHabitats[i].SetActive(false);
            //    LayeredHabitats[i].SetActive(false);
            //}
            for (int i = 0; i < AllbatchCounts[0]; i++)
            {
                allHabitats[i].SetActive(true);
                LayeredHabitats[i].SetActive(true);
            }
            activeData = 1;
            ParallelCoordInstantiator.delete();
            DataManager.LoadEnvData("species_parallel_allSpecies", 49, ServerStream.dataList1);
            displayParallelCoord();
        }
        if (Input.GetKeyDown("2"))
        {
            ModelInstantiator.hideAll();
            for (int i = AllbatchCounts[0]; i < AllbatchCounts[1]; i++)
            {
                allHabitats[i].SetActive(true);
                LayeredHabitats[i].SetActive(true);
            }
            activeData = 2;
            ParallelCoordInstantiator.delete();
            DataManager.LoadEnvData("species_parallel_allSpecies", 49, ServerStream.Reptile1);
            displayParallelCoord();
        }
        if (Input.GetKeyDown("3"))
        {
            ModelInstantiator.hideAll();
            for (int i = AllbatchCounts[1]; i < AllbatchCounts[2]; i++)
            {
                allHabitats[i].SetActive(true);
                LayeredHabitats[i].SetActive(true);
            }
            activeData = 3;
            ParallelCoordInstantiator.delete();
            DataManager.LoadEnvData("species_parallel_allSpecies", 49, ServerStream.algae1);
            displayParallelCoord();
        }
        if (Input.GetKeyDown("4"))
        {
            ModelInstantiator.hideAll();
            for (int i = AllbatchCounts[2]; i < AllbatchCounts[3]; i++)
            {
                allHabitats[i].SetActive(true);
                LayeredHabitats[i].SetActive(true);
            }
            activeData = 4;
            ParallelCoordInstantiator.delete();
            DataManager.LoadEnvData("species_parallel_allSpecies", 49, ServerStream.Amphibian1);
            displayParallelCoord();
        }
        if (Input.GetKeyDown("5"))
        {
            ModelInstantiator.hideAll();
            for (int i = AllbatchCounts[3]; i < AllbatchCounts[4]; i++)
            {
                allHabitats[i].SetActive(true);
                LayeredHabitats[i].SetActive(true);
            }
            activeData = 5;
            ParallelCoordInstantiator.delete();
            DataManager.LoadEnvData("species_parallel_allSpecies", 49, ServerStream.Fish1);
            displayParallelCoord();
        }
        if (Input.GetKeyDown("6"))
        {
            ModelInstantiator.hideAll();
            for (int i = AllbatchCounts[4]; i < AllbatchCounts[5]; i++)
            {
                allHabitats[i].SetActive(true);
                LayeredHabitats[i].SetActive(true);
            }
            activeData = 6;
            ParallelCoordInstantiator.delete();
            DataManager.LoadEnvData("species_parallel_allSpecies", 49, ServerStream.Mammal1);
            displayParallelCoord();
        }
        if (Input.GetKeyDown("7"))
        {
            ModelInstantiator.hideAll();
            for (int i = AllbatchCounts[5]; i < AllbatchCounts[6]; i++)
            {
                allHabitats[i].SetActive(true);
                LayeredHabitats[i].SetActive(true);
            }
            activeData = 7;
            ParallelCoordInstantiator.delete();
            DataManager.LoadEnvData("species_parallel_allSpecies", 49, ServerStream.Bird1);
            displayParallelCoord();
        }
        if (Input.GetKeyDown("8"))

        {
            ModelInstantiator.hideAll();
            for (int i = AllbatchCounts[6]; i < AllbatchCounts[7]; i++)
            {
                allHabitats[i].SetActive(true);
                LayeredHabitats[i].SetActive(true);
            }
            activeData = 8;
            ParallelCoordInstantiator.delete();
            DataManager.LoadEnvData("species_parallel_allSpecies", 49, ServerStream.Plant11);
            displayParallelCoord();
        }
        if (Input.GetKeyDown("9"))
        {
            ModelInstantiator.hideAll();
            for (int i = AllbatchCounts[7]; i < AllbatchCounts[8]; i++)
            {
                allHabitats[i].SetActive(true);
                LayeredHabitats[i].SetActive(true);
            }
            activeData = 9;
            ParallelCoordInstantiator.delete();
            DataManager.LoadEnvData("species_parallel_allSpecies", 49, ServerStream.Plant21);
            displayParallelCoord();
        }
        if (Input.GetKeyDown("0"))
        {
            ModelInstantiator.hideAll();
            for (int i = AllbatchCounts[8]; i < AllbatchCounts[9]; i++)
            {
                allHabitats[i].SetActive(true);
                LayeredHabitats[i].SetActive(true);
            }
            activeData = 10;
            ParallelCoordInstantiator.delete();
            DataManager.LoadEnvData("species_parallel_allSpecies", 49, ServerStream.Plant31);
            displayParallelCoord();
        }
        if (Input.GetKeyDown("b"))
        {
            ParallelCoordInstantiator.delete();
        }
        if (Input.GetKeyDown("z"))
        {
            //Subspaces.Highlight();
            //initHistory();
            //for (int i = 0; i < allHabitats.Count; i++)
            //{
            //    allHabitats[i].SetActive(true);
            //    //LayeredHabitats[i].SetActive(true);
            //}
        }
    }