コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        activeScene = SceneManager.GetActiveScene().name;

        if (activeScene == "circuitBuilderScene" || activeScene == "circuitBuilderTutorial")
        {
            if (circuitBuilder == null)
            {
                loadAndPrepScene("circuitBuilderTutorial");
            }
            if (Input.GetMouseButtonDown(1))
            {
                Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit2D hit = Physics2D.GetRayIntersection(ray, Mathf.Infinity, circuitBuilder.Mask);
                if (hit.collider != null && hit.transform.name.EndsWith("(Clone)"))
                {
                    if (circuitBuilder.SelectedGateCollider == hit.collider) // Right click on a Red Circle to delete a line
                    {
                        Destroy(circuitBuilder.RedCircle);
                        circuitBuilder.RedCircle            = null;
                        circuitBuilder.RedCircleHolder      = null;
                        circuitBuilder.SelectedGateCollider = null;
                        circuitBuilder.RemoveColliderAndItsPairsFromList(hit.collider);
                    }

                    else if (hit.collider.offset.x == 0)  // Right click on a gate's main body to delete it and any connected lines
                    {
                        circuitBuilder.RemoveGateFromList(hit.collider.gameObject);
                        if (circuitBuilder.RedCircleHolder == hit.collider.gameObject)
                        {
                            Destroy(circuitBuilder.RedCircle);
                            circuitBuilder.RedCircle            = null;
                            circuitBuilder.RedCircleHolder      = null;
                            circuitBuilder.SelectedGateCollider = null;
                        }

                        Destroy(hit.collider.gameObject);
                    }
                }
            }
        }
    }