void Update() { if (ManageWalls.ActiveWalls.Count == ManageWalls.WallList.Count && ManageWalls.ActiveWalls.Count != 0) { ManageWalls.Assignable = false; } else if (Assigning && ManageWalls.Assignable && !String.Equals(gameObject.tag, "out", StringComparison.OrdinalIgnoreCase)) { //Assign the Number, get next Wall to assign AssignValues(); gameObject.layer = 0; ManageWalls.ActiveWalls.Add(gameObject); OverlappingObjects = Physics2D.OverlapBoxAll(CheckBoxPos, new Vector2(1.55f, 1.55f), 0, Walls); gameObject.layer = 11; Assigning = false; if (FirstWall == null) { FirstWall = gameObject; } foreach (Collider2D OverlappedObj in OverlappingObjects) { if (!string.Equals(OverlappedObj.tag, "out", StringComparison.OrdinalIgnoreCase) && (OverlappedObj.gameObject == FirstWall || ManageWalls.ActiveWalls.Contains(OverlappedObj.gameObject) == false)) { OverlappedObj.GetComponent <Overlapping2>().Assigning = true; break; } } } //change layer, so only relevant wall get ontriggerhit // if Wall 0 is out, get new Wall to be 0 if (Assigning && string.Equals(gameObject.name, "out", StringComparison.OrdinalIgnoreCase)) { foreach (MainScript.Wallprops wall in MainScript.WallpropsList) { if (string.Equals(wall.Wall.tag, "TopWalls", StringComparison.OrdinalIgnoreCase)) { PossibleStarters.Add(wall.Wall); //wall.Wall.GetComponent<Overlapping2>().Assigning = true; //break; } } if (PossibleStarters.Count != 0) { PossibleStarters.Sort((x, y) => x.transform.position.x.CompareTo(y.transform.position.x)); PossibleStarters[0].GetComponent <Overlapping2>().Assigning = true; Assigning = false; } } }
void Update() { if (ManageWalls.ActiveWalls.Count == ManageWalls.WallList.Count && ManageWalls.ActiveWalls.Count != 0) { ManageWalls.Assignable = false; } else if (Assigning == true && ManageWalls.Assignable == true && gameObject.tag != "out") { //Assign the Number, get next Wall to assign Collider2D[] OverlappingObjects; AssignValues(); gameObject.layer = 0; ManageWalls.ActiveWalls.Add(gameObject); OverlappingObjects = Physics2D.OverlapBoxAll(CheckBoxPos, new Vector2(1.55f, 1.55f), 0, GameObject.Find("Main Camera").GetComponent <ManageWalls>().PossibleWalls); Assigning = false; if (FirstWall == null) { FirstWall = gameObject; } foreach (Collider2D OverlappedObj in OverlappingObjects) { if (OverlappedObj.gameObject.tag != "out" && OverlappedObj.gameObject == FirstWall) { OverlappedObj.GetComponent <Overlapping2>().Assigning = true; break; } else if (OverlappedObj.gameObject.tag != "out" && ManageWalls.ActiveWalls.Contains(OverlappedObj.gameObject) == false) { OverlappedObj.GetComponent <Overlapping2>().Assigning = true; break; } } } //change tag, so only relevant wall get ontriggerhit if (gameObject.tag == "RightWalls" || gameObject.tag == "LeftWalls" && gameObject.name != "out") { if (RayCastRotation.LastAxis == Axis.Vertical) { gameObject.layer = 12; } else { gameObject.layer = 11; } } else if (gameObject.tag == "TopWalls" || gameObject.tag == "DownWalls" && gameObject.name != "out") { if (RayCastRotation.LastAxis == Axis.Horizontal) { gameObject.layer = 12; } else { gameObject.layer = 11; } } // if Wall 0 is out, get new Wall to be 0 if (Assigning && gameObject.name == "out") { foreach (Shortestpath3.Wallprops wall in Shortestpath3.WallpropsList) { if (wall.Wall.tag == "TopWalls") { PossibleStarters.Add(wall.Wall); //wall.Wall.GetComponent<Overlapping2>().Assigning = true; //break; } } if (PossibleStarters.Count != 0) { PossibleStarters.Sort((x, y) => x.transform.position.x.CompareTo(y.transform.position.x)); PossibleStarters[0].GetComponent <Overlapping2>().Assigning = true; Assigning = false; // print("lol"); } } }