예제 #1
0
 // Use this for initialization
 void Awake()
 {
     Portal1 = GameObject.Instantiate(P1Prefab);
     Portal2 = GameObject.Instantiate(P2Prefab);
     Portal1.SetActive(false);
     Portal2.SetActive(false);
     portalLength = Portal1.GetComponent <BoxCollider2D>().size.y *3;
     PPos         = new PortalPosition(Portal1.transform.position, Portal2.transform.position);
 }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        //Create ray cast from player position to the platform
        if ((Input.GetButtonDown("Fire1") || Input.GetButtonDown("Fire2")) && !paused)
        {
            int platforms = LayerMask.GetMask("PortalPlatform", "Platform", "Barrier");
            int badportal;
            if (Input.GetButtonDown("Fire1"))
            {
                badportal = LayerMask.GetMask("Portal2");
            }
            else
            {
                badportal = LayerMask.GetMask("Portal1");
            }
            int pplatform = LayerMask.NameToLayer("PortalPlatform");

            Vector2 pos = transform.position;

            Vector2 target    = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2 direction = target - pos;

            RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, Mathf.Infinity, platforms | badportal);

            if (hit && hit.collider.gameObject.layer == pplatform)
            {
                Quaternion rotation = GetPortalRotation(hit);

                bool    makePortal = true;
                Vector2 consol     = PortalPositionConsolidation(ref makePortal, hit);
                Vector3 portalPos  = new Vector3(consol.x, consol.y, 0);

                if (Input.GetButtonDown("Fire1") && makePortal) //If right mouse click
                {
                    Portal1.SetActive(true);
                    Portal1.transform.rotation = rotation;
                    Portal1.transform.position = portalPos - (Portal1.transform.right * .2f);

                    PPos.p1   = Portal1.transform.position;
                    PPos.p1Or = shotOr;
                }
                else if (Input.GetButtonDown("Fire2") && makePortal)   //if left mouse click
                {
                    Portal2.SetActive(true);
                    Portal2.transform.rotation = rotation;
                    Portal2.transform.position = portalPos - (Portal2.transform.right * .2f);
                    PPos.p2   = Portal2.transform.position;
                    PPos.p2Or = shotOr;
                }
            }
        }
    }