예제 #1
0
    public void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            var shouldContinue = Enumerator.MoveNext();

            var convertedPath = Pathfinder.Path
                                .Select(item => item.Position.ToVector3XZ())
                                .ToArray();
            Line.DrawLine(convertedPath);

            if (!shouldContinue)
            {
                Debug.Log("Finished..");
            }
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            SceneManager.LoadScene(0);
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            StartCoroutine("WalkerAutomatic");
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            RepeatedWalker(RepeatedWalkerRepeats);
        }

        if (Input.GetKeyDown(KeyCode.A))
        {
            StartToGeneratePath();
            var tryCount = 0;
            while (Pathfinder.PathLength != 9)
            {
                if (tryCount++ > 1000)
                {
                    Debug.LogWarning("Failed.");
                    break;
                }
                QuickWalker();
            }
            Debug.Log("Tries: " + tryCount);
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Vector2 mousePos2D = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            Vector2 dir        = Vector2.zero;

            RaycastHit2D hit = Physics2D.Raycast(mousePos2D, dir);
            if (hit != null && hit.collider != null)
            {
                tempDragObject = hit.transform.gameObject;
                //hit.transform.position = mousePos2D;
                hit.transform.Find("Coord").GetComponent <TextMeshProUGUI>().text = mousePos2D.ToString();
                var dotsPos = dots.Select(item => item.gameObject.transform.position).ToArray();
                line.DrawLine(dotsPos);
            }

            if (tempDragObject != null)
            {
                tempDragObject.transform.position = mousePos2D;
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            tempDragObject = null;
            FindTriangleLefttoRight();
        }
    }