void Start() { //we load up the initial level, which will consist of the player, the ship, the guitext, a random GameObject containing this script, and the camera. //camera has the focus set to the player, the ship has the focus set to the player Generate (0, 0); //generate a square of width = initial_distance * 2; Generate (initial_distance * 2, 0); Generate (initial_distance * 2, initial_distance * 2); Generate (0, initial_distance * 2); Generate (initial_distance * -2, 0); Generate (initial_distance * -2, initial_distance * -2); Generate (0, initial_distance * -2); Generate (initial_distance * 2, initial_distance * -2); Generate (initial_distance * -2, initial_distance * 2); //Create the EdgeCollider2D boundaries for the initial area topEdge.initialDistance = initial_distance; // topEdge.GetComponent<EdgeCollider2D> ().isTrigger = true; // topEdge.GetComponent<Transform> ().position = new Vector3 (0, initial_distance, 0); // topEdge.GetComponent<Transform> ().rotation = new Quaternion (0, 0, 90, 0); topEdge = (Edgebounds)Instantiate (topEdge,new Vector3(0,initial_distance,0),new Quaternion(0,0,0,0)); bottomEdge = (Edgebounds)Instantiate (bottomEdge,new Vector3(0,-initial_distance,0),new Quaternion(0,0,0,0)); bottomEdge.transform.Rotate (new Vector3 (0, 0, 180)); leftEdge = (Edgebounds)Instantiate (leftEdge,new Vector3(-initial_distance,0,0),new Quaternion(0,0,0,0)); leftEdge.transform.Rotate (new Vector3 (0, 0, 90)); rightEdge = (Edgebounds)Instantiate (rightEdge,new Vector3(initial_distance,0,0),new Quaternion(0,0,0,0)); rightEdge.transform.Rotate (new Vector3 (0, 0, 270)); }
//create new script for this void OnTriggerEnter2D(Collider2D thing) { Edgebounds eC; // detecting if it is in the same space as another EdgeCollider2D // if it is it will delete that object and itself if(thing.GetComponentInParent<Edgebounds>() != null){ eC = thing.GetComponentInParent<Edgebounds>(); if(this.edgePos.x == eC.edgePos.x){ if(this.edgePos.y == eC.edgePos.y){ Destroy(eC.gameObject); Destroy(this.gameObject); } } } // Creates the 3 borders then destroys itself if (thing == p.GetComponent<PolygonCollider2D>()) { //instantiates the foward one fowardEdge = (Edgebounds)Instantiate(fowardEdge,fowardCoords(facingVect),facing); fowardEdge.initialDistance = this.initialDistance; //one to the right of the foward rightEdge = (Edgebounds)Instantiate(rightEdge,rightCoords(facingVect),facing); rightEdge.transform.Rotate(new Vector3(0,0,-90)); rightEdge.initialDistance = this.initialDistance; //one to the left of the foward leftEdge = (Edgebounds)Instantiate(leftEdge,leftCoords(facingVect),facing); leftEdge.transform.Rotate(new Vector3(0,0,90)); leftEdge.initialDistance = this.initialDistance; //Generates stuff within the boundaries //needs to generate from bottom left to top right GameObject ProcGenController = GameObject.Find ("ProcGenController"); switch((int)facingVect.z){ case(270): //generate a 1x3 block right of the entered region ProcGenController.GetComponent<ProcGen>().Generate(edgePos.x + initialDistance * 3, edgePos.y + initialDistance * 2); ProcGenController.GetComponent<ProcGen>().Generate(edgePos.x + initialDistance * 3, edgePos.y + initialDistance * 0); ProcGenController.GetComponent<ProcGen>().Generate(edgePos.x + initialDistance * 3, edgePos.y + initialDistance * -2); break; case(0): //genrate a 3x1 block above the entered region ProcGenController.GetComponent<ProcGen>().Generate(edgePos.x + initialDistance * 2, edgePos.y + initialDistance * 3); ProcGenController.GetComponent<ProcGen>().Generate(edgePos.x + initialDistance * 0, edgePos.y + initialDistance * 3); ProcGenController.GetComponent<ProcGen>().Generate(edgePos.x + initialDistance * -2, edgePos.y + initialDistance * 3); break; case(180): //genrate a 3x1 block below the entered region ProcGenController.GetComponent<ProcGen>().Generate(edgePos.x + initialDistance * 2, edgePos.y + initialDistance * -3); ProcGenController.GetComponent<ProcGen>().Generate(edgePos.x + initialDistance * 0, edgePos.y + initialDistance * -3); ProcGenController.GetComponent<ProcGen>().Generate(edgePos.x + initialDistance * -2, edgePos.y + initialDistance * -3); break; case(90): //generate a 1x3 block left of the entered region ProcGenController.GetComponent<ProcGen>().Generate(edgePos.x + initialDistance * -3, edgePos.y + initialDistance * 2); ProcGenController.GetComponent<ProcGen>().Generate(edgePos.x + initialDistance * -3, edgePos.y + initialDistance * 0); ProcGenController.GetComponent<ProcGen>().Generate(edgePos.x + initialDistance * -3, edgePos.y + initialDistance * -2); break; } Destroy (this.gameObject); } }