Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (GameObject.FindGameObjectWithTag("Line") == null)
        {
            WaitingLinesStartingPoint.Clear();
            WaitingLinesEndingPoint.Clear();
            return;
        }
        if (Input.GetKeyDown(KeyCode.Q))
        {
            logtool.QuitGame();
            logtool.SaveLog();
            SceneManager.LoadScene("World Scene");
        }
        if (!unfolding && WaitingLinesStartingPoint.ToArray().Length != 0)
        {
            Vector3 midPoint = (WaitingLinesStartingPoint[0] + WaitingLinesEndingPoint[0]) / 2;

            PreviousStartingPoint.Add(WaitingLinesStartingPoint[0]);
            PreviousEndingPoint.Add(WaitingLinesEndingPoint[0]);

            WaitingLinesStartingPoint.RemoveAt(0);
            WaitingLinesEndingPoint.RemoveAt(0);
            ClickAtLine(midPoint);
        }

        if (!unfolding && Input.GetMouseButtonDown(0))
        {
            RaycastHit hitObject = new RaycastHit();
            Ray        ray       = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hitObject) && hitObject.transform.tag == "Line")
            {
                Vector3 startingPoint = hitObject.transform.GetComponent <LineRenderer>().GetPosition(0);
                Vector3 endingPoint   = hitObject.transform.GetComponent <LineRenderer>().GetPosition(1);

                //Destroy the Line.
                hitObject.transform.GetComponent <Glow>().destroyLine();

                //Instead of destroying the line, we change its color to grey.
                //hitObject.transform.GetComponent<BoxCollider>().enabled = false;
                //hitObject.transform.GetComponent<Glow>().ChangeToGray();

                Vector3 midPoint = (startingPoint + endingPoint) / 2;

                HasFoldedBack = false;
                PreviousStartingPoint.Clear();
                PreviousEndingPoint.Clear();
                PreviousUnfoldingA.Clear();
                PreviousUnfoldingB.Clear();
                PreviousStartingNormalA.Clear();
                PreviousStartingNormalB.Clear();

                ClickAtLine(midPoint);

                logtool.LineClick(startingPoint, endingPoint);

                PreviousStartingPoint.Add(startingPoint);
                PreviousEndingPoint.Add(endingPoint);
            }
        }
    }