Example #1
0
    void OnMouseDown()
    {
        if (!pause)
        {
            //Debug.Log("pause" + pause);
            var v3 = Input.mousePosition;
            v3.z = distance;
            pos  = Camera.main.ScreenToWorldPoint(v3);
            if (pos.x > 0)
            {
                pos.x = Mathf.Round((int)pos.x / 2) * 2 + 1;
            }
            if (pos.x <= 0)
            {
                pos.x = Mathf.Round((int)pos.x / 2) * 2 - 1;
            }
            if (pos.y < 0)
            {
                pos.y = Mathf.Round((int)pos.y / 2) * 2 - 1;
            }
            if (pos.y >= 0)
            {
                pos.y = Mathf.Round((int)pos.y / 2) * 2 + 1;
            }
            //Debug.Log("OnMouseDown " + pos);
            mouseDown = true;
            if (isSafePlant((int)pos.x, (int)pos.y))
            {
                if (input)
                {
                    GameObject obj = (GameObject)Instantiate(backgroundIn, pos, Quaternion.identity);
                    // obj.AddComponent<RemovePortal>();
                    obj.AddComponent <PortalId>();
                    obj.GetComponent <Renderer>().material.color = portalColor;
                    //obj.GetComponent<Renderer>().material.mainTexture = inPortal;
                    obj.GetComponent <SpriteRenderer>().sprite = inPortal;
                    inPos = pos;
                    //Debug.Log("inPos: " + pos);

                    PortalId idOfNewPortal = obj.GetComponent <PortalId>();
                    idOfNewPortal.setId(id);
                    por = new InputPortal(id);
                    por.InputPortalGO = obj;
                    input             = false;
                }
                else
                {
                    currentOutputPortal = (GameObject)Instantiate(backgroundOut, pos, Quaternion.identity);
                    //currentOutputPortal.AddComponent<RemovePortal>();
                    currentOutputPortal.AddComponent <PortalId>();
                    currentOutputPortal.GetComponent <Renderer>().material.color = portalColor;
                    currentOutputPortal.GetComponent <SpriteRenderer>().sprite   = inPortal;
                    PortalId idOfNewPortal = currentOutputPortal.GetComponent <PortalId>();
                    idOfNewPortal.setId(id);
                    outputPortal = true;
                    input        = true;
                }
            }
        }
    }