public void MakeItem() { script = object_manager.GetComponent <ObjectManager_>(); h = g.GetComponent <Hole>(); int i = 0, x = 0, y = 0; int mapsize = Mathf.RoundToInt(script.gridWorldSize.x); int house_cnt = (mapsize / 2) + 1; //맵 한 줄의 길이/2==설치할 아이템의 수 do { x = Random.Range(0, mapsize - 1); y = Random.Range(0, mapsize - 1); if ((script.grid[x, y].is_trap == false) && (script.grid[x, y].is_lighthouse == false) && (script.grid[x, y].is_Item == false)) //트랩 또는 등대 또는 아이템이 이미 설치되있냐 { int valid = 1; //등대를 설치해도되는 위치냐 //nqueen problem으로 해보기!!!그러나 똑같은 배치만 나올 수도 있다, 리커젼 풀리는 순서가 같기때문 if (((x == 0) && (y == 0)) || ((x == mapsize - 1) && (y == mapsize - 1))) { valid = 0; } if (valid == 1) { Transform newhouse = Instantiate(item); newhouse.position = new Vector3(script.grid[x, y].worldPosition.x, script.grid[x, y].worldPosition.y); script.grid[x, y].is_Item = true; i++; } } } while (i != house_cnt); }
public void light_house() { script = object_manager.GetComponent <ObjectManager_>(); int i = 0, x = 0, y = 0; int mapsize = Mathf.RoundToInt(script.gridWorldSize.x); int house_cnt = (mapsize / 2) + 1; //맵 한 줄의 길이/2==설치할 등대의 수 do { x = Random.Range(0, mapsize - 1); y = Random.Range(0, mapsize - 1); if ((script.grid[x, y].is_trap == false) && (script.grid[x, y].is_lighthouse == false)) //트랩 또는 등대가 이미 설치되있냐 { int valid = 1; //등대를 설치해도되는 위치냐 //nqueen problem으로 해보기!!!그러나 똑같은 배치만 나올 수도 있다, 리커젼 풀리는 순서가 같기때문 if (((x == 0) && (y == 0)) || ((x == mapsize - 1) && (y == mapsize - 1))) //그럼 예외를 몇 개하고 길 없을때마다 다시 배치하는건?확률을 명확히 따져봐야 할 것, { valid = 0; } if (valid == 1) { GameObject newhouse = Instantiate(house); newhouse.transform.position = new Vector3(script.grid[x, y].worldPosition.x, script.grid[x, y].worldPosition.y, 2); script.grid[x, y].is_lighthouse = true; i++; } } } while (i != house_cnt); }
public void Trap() { script = object_manager.GetComponent <ObjectManager_>(); int i = 0, x = 0, y = 0; int mapsize = Mathf.RoundToInt(script.gridWorldSize.x); int hole_cnt = mapsize; //맵 한 줄의 길이==설치할 구멍의 수 holes = new GameObject[mapsize + 2]; int h = 0; do { x = Random.Range(0, mapsize - 1); y = Random.Range(0, mapsize - 1); if (script.grid[x, y].is_trap == false) //트랩 이미 설치되있냐 { int valid = 1; //트랩을 설치해도되는 위치냐 //nqueen problem으로 해보기!!!그러나 똑같은 배치만 나올 수도 있다, 리커젼 풀리는 순서가 같기때문 if (((x == 0) && (y == 0)) || ((x == mapsize - 1) && (y == mapsize - 1))) //그럼 예외를 몇 개하고 길 없을때마다 다시 배치하는건?확률을 명확히 따져봐야 할 것, { valid = 0; } if (valid == 1) { newhole = Instantiate(hole); newhole.transform.position = new Vector3(script.grid[x, y].worldPosition.x, script.grid[x, y].worldPosition.y, 2); script.grid[x, y].is_trap = true; holes[h] = newhole; // 실제 오브젝트를 따로 배열에 저장함 => 아이템에서 실제 오브젝트를 건드려야해서 h++; i++; } } } while (i != hole_cnt + 2); // 2개 더 늘림 }
/* 아이템 먹으면 해당 bool 값이 true 됨 = 활성화 * 활성화 된 아이템은 스크립트 작동함*/ public void OBD_MakeBlock() // 고물 탐지기 사용시 타일 까는 메소드 { // 1. 맵 범위 안에서 2. 현재 플레이어 위치 중심 3. 8방위 조건만족하면 타일 생성하도록, 등대에는 생성되면 안됨! script = object_manager.GetComponent <ObjectManager_>(); // 무브포인트의 위치 = 타일 생성하는 곳임 int n = 10; Vector2 over = new Vector2(script.gridWorldSize.x * 5, script.gridWorldSize.y * 5); // 맵 사이즈 저장 int mapsize = Mathf.RoundToInt(script.gridWorldSize.x); for (int i = 1; i < 4; i++) // 123 369 - 123 = 210, 543, 876 하면 배열 0부터 8번까지 저장 { // 8방위 for (int j = 1; j < 4; j++) // 123 { int countL = 0; MPpoisition = new Vector2(playerPoint.position.x + n * (i - 2), playerPoint.position.y + n * (j - 2)); // -1, 0, 1 // 타일 깔 위치는 for문 돌릴때마다 위치 바껴야해서 if (i == 2 && j == 2) // 중심에는 만들 필요 없음 { continue; } for (int x = 0; x < mapsize; x++) { // 무브 포인트와 등대가 부딪히면 예외카운트 + 이말은 생성 안한다는 말임 for (int y = 0; y < mapsize; y++) { if (script.grid[x, y].worldPosition == MPpoisition) // 무브포인트와 일치할때 { if (script.grid[x, y].is_lighthouse == true) // 해당 위치가 등대일때 생성안함 { countL++; } } } } if (countL == 0) { if (MPpoisition.x > over.x || MPpoisition.x < -over.x || MPpoisition.y > over.y || MPpoisition.y < -over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newOneBlockPoint[i * 3 - j] = Instantiate(OneBlockPoint); // 생성 newOneBlockPoint[i * 3 - j].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); } } } } }
// Use this for initialization void Start() { life = maxLife; script = object_manager.GetComponent <ObjectManager_>(); PlayerRoundHoles = GameObject.FindGameObjectWithTag("PlayerRoundHoles").GetComponent <Text>(); playerPoint.position = new Vector2(-(script.gridWorldSize.x * 5) + 5, (script.gridWorldSize.y * 5) - 5); movePoint(); StartCoroutine(CoMove()); //코루틴 시작 f = g.GetComponent <Hole>(); }
public int is_root_interface() { script = object_manager.GetComponent <ObjectManager_>(); int lastx, lasty; //도착지점의 좌표와 큐의 새로운 값을 받을때 들어가는 인덱스 script.grid[0, 0].bfs_distance = 1; lastx = Mathf.RoundToInt(script.gridWorldSize.x) - 1; lasty = Mathf.RoundToInt(script.gridWorldSize.y) - 1; return(bfs_(script.grid[0, 0], lastx, lasty)); }
public void EBScript() { GameObject.Find("Item_Button2").GetComponent <Button>().enabled = false; int mapsize = Mathf.RoundToInt(script.gridWorldSize.x); script = object_manager.GetComponent <ObjectManager_>(); Vector3 ViewEightBlockPoint; if (EBD == true) { // 사용 즉시 8방위의 구멍이 보여야함 for (int i = 1; i < 4; i++) { // 8방위 for (int j = 1; j < 4; j++) { ViewEightBlockPoint = new Vector2(playerPoint.position.x + 10 * (i - 2), playerPoint.position.y + 10 * (j - 2)); for (int z = 0; z < mapsize + 2; z++) // 마우스 클릭한 블록에 구멍이 있을때 구멍 위치 -1로 해서 보이게함 { if (h.holes[z].transform.position.x == ViewEightBlockPoint.x && h.holes[z].transform.position.y == ViewEightBlockPoint.y) { Transform ht1 = h.holes[z].GetComponent <Transform>(); ht1.transform.position = new Vector3(h.holes[z].transform.position.x, h.holes[z].transform.position.y, -1); } } } } EBD = false; // 다시 아이템을 없는 상태로 만들고 UIManager.EBD = false; usedItem++; // 아이템 사용 횟수 +1 for (int k = 0; k < 3; k++) // 인벤토리 전체 검사해서 해당 아이템이 위치했던 배열을 null로 초기화 { if (Inventory[k] == "EightBlockDetector") // 여덟 블록 탐지기 제거 { Inventory[k] = null; // 배열 초기화 Debug.Log("탐지기 사용완료2" + EBD); } } chColor2.normalColor = Color.white; b2.GetComponent <Button>().colors = chColor2; // 이걸 다시 집어넣어줘야 색이 바뀜 GameObject.Find("Item_Button2").GetComponent <Button>().enabled = true; } }
public void MakeItem() { script = object_manager.GetComponent <ObjectManager_>(); h = g.GetComponent <Hole>(); Vector3 itemPosition; int i = 0, x = 0, y = 0; int mapsize = Mathf.RoundToInt(script.gridWorldSize.x); int house_cnt = (mapsize / 2) + 1; //맵 한 줄의 길이/2==설치할 아이템의 수 do { x = Random.Range(0, mapsize - 1); y = Random.Range(0, mapsize - 1); for (int k = 0; k < mapsize; k++) { for (int g = 0; g < mapsize; g++) { itemPosition = new Vector2(-(script.gridWorldSize.x * 5) + 5 + 10 * x, (script.gridWorldSize.y * 5) - 5 - 10 * y); if (itemPosition == script.grid[k, g].worldPosition) // 랜덤위치와 첫번째부터(0,0)~(끝,끝) 위치 비교한다. { if ((script.grid[k, g].is_trap == false) && (script.grid[k, g].is_lighthouse == false)) //트랩 또는 등대가 이미 설치되있냐 { int valid = 1; //등대를 설치해도되는 위치냐 //nqueen problem으로 해보기!!!그러나 똑같은 배치만 나올 수도 있다, 리커젼 풀리는 순서가 같기때문 if (((x == 0) && (y == 0)) || ((x == mapsize - 1) && (y == mapsize - 1))) { valid = 0; } if (valid == 1) { Transform newhouse = Instantiate(item); newhouse.position = new Vector3(script.grid[k, g].worldPosition.x, script.grid[k, g].worldPosition.y); i++; } } } } } } while (i != house_cnt); }
private void OnTriggerEnter2D(Collider2D Player) { script = object_manager.GetComponent <ObjectManager_>(); int mapsize = Mathf.RoundToInt(script.gridWorldSize.x); if (Player.gameObject.tag == "Hole") { life -= 1; // 라이프 까짐 for (int i = 0; i < mapsize; i++) // 마우스 클릭한 블록에 구멍이 있을때 구멍 위치 -1로 해서 보이게함 { if (f.holes[i].transform.position.x == playerPoint.position.x && f.holes[i].transform.position.y == playerPoint.position.y) { Transform ht1 = f.holes[i].GetComponent <Transform>(); ht1.transform.position = new Vector3(f.holes[i].transform.position.x, f.holes[i].transform.position.y, -1); } } Debug.Log(life); } }
void CreateGrid() { script = object_manager.GetComponent <ObjectManager_>(); gridSizeX = Mathf.RoundToInt(script.gridWorldSize.x) * 10; gridSizeY = Mathf.RoundToInt(script.gridWorldSize.y) * 10; script.grid = new Node[Mathf.RoundToInt(script.gridWorldSize.x), Mathf.RoundToInt(script.gridWorldSize.y)]; //Vector3 worldTopLeft = transform.position - (Vector3.right * gridSizeX / 2) + Vector3.forward * gridSizeY / 2; //(0,0에서 x크기만큼 빼고 y크기만큼 더했으니 맵의 좌상이 0,0이 된다.) for (int i = 0; i < script.gridWorldSize.x; i++) { for (int j = 0; j < script.gridWorldSize.y; j++) { // 현재 노드의 좌표 ((맵에서 좌상 =0,0) - 0,5 ) Vector2 worldPosition = new Vector2(-(gridSizeX / 2) + 5 + 10 * j, (gridSizeY / 2) - 5 - 10 * i); script.grid[i, j] = new Node(worldPosition); Transform newBlock = Instantiate(block); newBlock.position = new Vector3(script.grid[i, j].worldPosition.x, script.grid[i, j].worldPosition.y); } } }
// Update is called once per frame void Update() { script = object_manager.GetComponent <ObjectManager_>(); int mapsize = Mathf.RoundToInt(script.gridWorldSize.x); for (int i = 0; i < mapsize + 2; i++) // 마우스 클릭한 블록에 구멍이 있을때 구멍 위치 -1로 해서 보이게함 { if (f.holes[i].transform.position.x == playerPoint.position.x && f.holes[i].transform.position.y == playerPoint.position.y) { Transform ht1 = f.holes[i].GetComponent <Transform>(); ht1.transform.position = new Vector3(f.holes[i].transform.position.x, f.holes[i].transform.position.y, -1); f.holes[i].GetComponent <AudioSource>().enabled = true; } } if (life == 0) { if (!gameOver) { Die(); } } end(); }
void Start() { //startTime = Time.time; life = maxLife; script = object_manager.GetComponent <ObjectManager_>(); script_bfs = GameObject.Find("Player").GetComponent <BFS>(); if (script_bfs.is_root_interface() == 1) { Debug.Log("exist"); } else { SceneManager.LoadScene("MAP1"); // 신 다시시작 } Debug.Log("No_exist"); print(script.getBFS_v()); script.print_distance(); //startTime = Time.time; life = maxLife; PlayerRoundHoles = GameObject.FindGameObjectWithTag("PlayerRoundHoles").GetComponent <Text>(); // 우측 상단 플레이어 중심 구멍수 택스트 playerPoint.position = new Vector2(-(script.gridWorldSize.x * 5) + 5, (script.gridWorldSize.y * 5) - 5); // 플레이어 시작 위치 지정 movePoint(); // 플레이어 시작 위치에 타일 까는작업 StartCoroutine(CoMove()); //코루틴 시작 = update와 거의 동일하다 보면됨(마우스 클릭 위치 실시간으로 받게됨) f = g.GetComponent <Hole>(); lifeObj1 = GameObject.Find("Life1"); // life 오브젝트 lifeObj2 = GameObject.Find("Life2"); lifeObj3 = GameObject.Find("Life3"); int mapsize = Mathf.RoundToInt(script.gridWorldSize.x); }
public void K_MakeBlock() { script = object_manager.GetComponent <ObjectManager_>(); int c = 0; int mapsize = Mathf.RoundToInt(script.gridWorldSize.x); // 1. 맵 범위 안에서 2. 현재 플레이어 위치 중심 3. 8방위 조건만족하면 타일 생성하도록, 등대에는 생성되면 안됨! // 무브포인트의 위치 = 타일 생성하는 곳임 int n = 10; for (int i = 1; i < 3; i++) // 12 { for (int j = 1; j < 6; j++) // 12345 { if (i == 1 && (j == 1 || j == 3 || j == 5)) { continue; } if (i == 2 && (j == 2 || j == 3 || j == 4)) { continue; } int countL1 = 0; int countL2 = 0; Kposition = new Vector2(playerPoint.position.x + n * (i - 3), playerPoint.position.y + n * (j - 3)); // -20, -10또는10 / -10, -20또는20 ReKposition = new Vector2(playerPoint.position.x - n * (i - 3), playerPoint.position.y - n * (j - 3)); Vector2 over = new Vector2(script.gridWorldSize.x * 5, script.gridWorldSize.y * 5); // 맵 사이즈 저장 for (int x = 0; x < mapsize; x++) { // 무브 포인트와 등대가 부딪히면 예외카운트 + 이말은 생성 안한다는 말임 for (int y = 0; y < mapsize; y++) { if (script.grid[x, y].worldPosition == Kposition) // 무브포인트와 일치할때 { if (script.grid[x, y].is_lighthouse == true) // 해당 위치가 등대일때 생성안함 { countL1++; Debug.Log("누락1"); } } else if (script.grid[x, y].worldPosition == ReKposition) // 무브포인트와 일치할때 { if (script.grid[x, y].is_lighthouse == true) // 해당 위치가 등대일때 생성안함 { countL2++; Debug.Log("누락2"); } } } } Debug.Log("ReKposition" + ReKposition); Debug.Log("Kposition" + Kposition); if (countL1 == 0) { if (Kposition.x >= 0 && Kposition.y >= 0) // 1사분면 { if (Kposition.x > over.x || Kposition.y > over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newKnightPoint[c] = Instantiate(KnightPoint); // 생성 newKnightPoint[c].transform.position = new Vector3(Kposition.x, Kposition.y); c++; } } else if (Kposition.x >= 0 && Kposition.y <= 0) // 4사분면 { if (Kposition.x > over.x || Kposition.y < -over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newKnightPoint[c] = Instantiate(KnightPoint); // 생성 newKnightPoint[c].transform.position = new Vector3(Kposition.x, Kposition.y); c++; } } else if (Kposition.x <= 0 && Kposition.y >= 0) // 2사분면 { if (Kposition.x < -over.x || Kposition.y > over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newKnightPoint[c] = Instantiate(KnightPoint); // 생성 newKnightPoint[c].transform.position = new Vector3(Kposition.x, Kposition.y); c++; } } else if (Kposition.x <= 0 && Kposition.y <= 0) //3사분면 { if (Kposition.x < -over.x || Kposition.y < -over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newKnightPoint[c] = Instantiate(KnightPoint); // 생성 newKnightPoint[c].transform.position = new Vector3(Kposition.x, Kposition.y); c++; } } } if (countL2 == 0) { if (ReKposition.x >= 0 && ReKposition.y >= 0) // 1사분면 { if (ReKposition.x > over.x || ReKposition.y > over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newKnightPoint[c] = Instantiate(KnightPoint); // 생성 newKnightPoint[c].transform.position = new Vector3(ReKposition.x, ReKposition.y); c++; } } else if (ReKposition.x >= 0 && ReKposition.y <= 0) // 4사분면 { if (ReKposition.x > over.x || ReKposition.y < -over.y) { Debug.Log("아마 여기서 누락"); continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newKnightPoint[c] = Instantiate(KnightPoint); // 생성 newKnightPoint[c].transform.position = new Vector3(ReKposition.x, ReKposition.y); c++; } } else if (ReKposition.x <= 0 && ReKposition.y >= 0) // 2사분면 { if (ReKposition.x < -over.x || ReKposition.y > over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newKnightPoint[c] = Instantiate(KnightPoint); // 생성 newKnightPoint[c].transform.position = new Vector3(ReKposition.x, ReKposition.y); c++; } } else if (ReKposition.x <= 0 && ReKposition.y <= 0) //3사분면 { if (ReKposition.x < -over.x || ReKposition.y < -over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newKnightPoint[c] = Instantiate(KnightPoint); // 생성 newKnightPoint[c].transform.position = new Vector3(ReKposition.x, ReKposition.y); c++; } // 홀수맵에서는 좌표가 0일 수가 있음;; x,y가 하나이상 0인 경우임 } } } } }
public void movePoint() { script = object_manager.GetComponent <ObjectManager_>(); int mapsize = Mathf.RoundToInt(script.gridWorldSize.x); // 1. 맵 범위 안에서 2. 현재 플레이어 위치 중심 3. 8방위 조건만족하면 타일 생성하도록, 등대에는 생성되면 안됨! // 무브포인트의 위치 = 타일 생성하는 곳임 int n = 10; int view = 0; // 플레이어 중심 8방위 구멍 개수 for (int i = 1; i < 4; i++) // 123 369 - 123 = 210, 543, 876 하면 배열 0부터 8번까지 저장 { // 8방위 for (int j = 1; j < 4; j++) // 123 { int countL = 0; MPpoisition = new Vector2(playerPoint.position.x + n * (i - 2), playerPoint.position.y + n * (j - 2)); // -1, 0, 1 Vector2 over = new Vector2(script.gridWorldSize.x * 5, script.gridWorldSize.y * 5); // 맵 사이즈 저장 /* 어이없는 부분에서 실수가 있었다. * 매번 MovePoint 배열에 새로 위치가 할당되고 지워지고 반복하는데 왜 지나온 길을 MovePoint 배열에 같이 썻지?? * 해결책 : TracePoint라는 새로운 오브젝트 배열에 집어넣었다. 어차피 나중에 점수 계산에 끌어다 쓰면 될듯. */ if (i == 2 && j == 2 && q == 0) { // 자기자신의 위치에는 지나온길 표시 TracePoint[t] = Instantiate(Trace); // 생성 TracePoint[t].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); t++; // 한 스테이지 안에서 유지되는 값 지나온 길 개수은 아무리 많이 만들어도 맵 크기 넘게는 못만듬 q++; Debug.Log("지나온 길 : " + t); } for (int x = 0; x < mapsize; x++) { // 무브 포인트와 등대가 부딪히면 예외카운트 + 이말은 생성 안한다는 말임 for (int y = 0; y < mapsize; y++) { if (script.grid[x, y].worldPosition == MPpoisition) // 무브포인트와 일치할때 { if (script.grid[x, y].is_lighthouse == true) // 해당 위치가 등대일때 생성안함 { countL++; } else if (script.grid[x, y].is_trap == true) { // 해당 위치가 구멍일때 생성안하면서 view값 +1 view++; } } } } if (countL == 0) // 간단하게 줄여보았음 굳이 1,2,3,4사분면 안 나눠도 이렇게 해도 ㄱㅊ { if (MPpoisition.x > over.x || MPpoisition.x < -over.x || MPpoisition.y > over.y || MPpoisition.y < -over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newMovePoint[i * 3 - j] = Instantiate(MovePointer); // 생성 newMovePoint[i * 3 - j].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); } } // 플레이어 중심 8방위에 구멍 수 출력 PlayerRoundHoles.text = view + ""; } } }
/* 깃발 설계 * update에 flag() 올려놔서 언제든 우클릭 받으면 생성하도록 * 우클릭 - 무언가에 히트될때(맵전체에 BoxColider2D 생성 되어 있으므로 맵 안에서만 작동됨 */ IEnumerator makeFlag() // 깃발 { script = object_manager.GetComponent <ObjectManager_>(); while (true) // 아이템 사용시에는 무브포인트가 잠시 비활성화 되야해서 이렇게했음 { if (Input.GetMouseButtonDown(1)) { test.enabled = false; // 무브포인트 중단 for (int i = 0; i < 9; i++) { DestroyObject(test.newMovePoint[i]); // 기존 위치 제거 + 지나온 길도 지워야함 } for (int i = 0; i < 2; i++) { DestroyObject(test.TracePoint[Player.t]); if (Player.t != 0) // 시작 지점에서 깃발 꼽을시엔 t=0이라 t-1 = -1 : 오류!! { Player.t -= 1; // 1빼줘라.. 안그럼 t값 무한대로 올라간다. } } /* 이제 확실히 알았다. * 정적 메소드나 정적 변수는 클래스.메소드 혹은 클래스.변수로 접근이 가능하다... * 만약 정적이 아니라면 객체를 만들어서 객체 변수.메소드 이딴식으로 해야된다 * 정적 변수가 아니면 이런 방식으로 (객체 변수.변수) 접근 불가능 그래서 get매소드 쓰는거다..!! */ Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //메인 카메라에서 마우스 위치(클릭한곳)로 광선발사 RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity); /* 굉장히 큰 문제점이 있다. * 마우스 클릭시 타일과 충돌 할 경우 깃발과 충돌 할 경우 2가지가 있는데 * 그게 내 마음대로 클릭되는게 아니다!... * 그냥 태그나 레이어로 구분지을 수 있는게 아님 * 깃발이 있는데도 타일을 누를수도 있어서 계속 버그가 발생한다. * * 두번째로 깃발의 위치를 저장하려하니 이 또한 문제가 있다. * 그냥 다른거처럼 할까? * */ if (hit == false) { // 히트된 게 없을때 => 이걸 추가하는 이유는 맵 밖으로 안나가게 하려고 } else // 충돌시 위치비교 정말 비효율적이지만 맵 전체 반복 돌려서 해당 위치를 가져온다. { for (int i = 0; i < script.gridWorldSize.x; i++) { for (int j = 0; j < script.gridWorldSize.y; j++) { if (script.grid[i, j].worldPosition == hit.collider.gameObject.transform.position) { if (script.grid[i, j].is_lighthouse) // 해당 위치에 등대가 있네 { // 걍 넘어가샘 } else if (script.grid[i, j].is_flag) // 이번엔 깃발이 있네 { //삭제 for (int z = 0; z < 100; z++) // 실제 깃발의 위치와 비교 { if (flagPos[z] != null && flagPos[z].transform.position == script.grid[i, j].worldPosition) { DestroyObject(flagPos[z]); } } } else // 아 아무것도 없네 { script.grid[i, j].is_flag = true; // 이 위치에는 등대를 만든다. flagPos[z] = Instantiate(flag); // 여기에 실제 오브젝트가 저장이 됨. flagPos[z].transform.position = script.grid[i, j].worldPosition; // 오브젝트의 위치지정 // 도저히 머리가 안돌아간다. 그냥 z값은 무한히 올라가게끔..어차피 몇 번 안쓸거임 z++; } } } } } yield return(new WaitForSeconds(0.3f)); test.movePoint(); // 새 위치 할당 test.enabled = true; // 다시 true값 넣어줘야 무브포인트가 작동을함 StartCoroutine(test.CoMove()); //무브포인트 코루틴 중단시킴 => 깃발이 자꾸 무브포인트에 꼽히는 버그가 생겨서 } yield return(null); } }
public void movePoint() { script = object_manager.GetComponent <ObjectManager_>(); int mapsize = Mathf.RoundToInt(script.gridWorldSize.x); // 1. 맵 범위 안에서 2. 현재 플레이어 위치 중심 3. 8방위 조건만족하면 타일 생성하도록, 등대에는 생성되면 안됨! // 무브포인트의 위치 = 타일 생성하는 곳임 int n = 10; int view = 0; // 플레이어 중심 8방위 구멍 개수 for (int i = 1; i < 4; i++) // 123 369 - 123 = 210, 543, 876 하면 배열 0부터 8번까지 저장 { // 8방위 for (int j = 1; j < 4; j++) // 123 { int countL = 0; MPpoisition = new Vector2(playerPoint.position.x + n * (i - 2), playerPoint.position.y + n * (j - 2)); // -1, 0, 1 Vector2 over = new Vector2(script.gridWorldSize.x * 5, script.gridWorldSize.y * 5); // 맵 사이즈 저장 if (i == 2 && j == 2) { // 자기자신의 위치에는 지나온길 표시 newMovePoint[i * 3 - j] = Instantiate(Trace); // 생성 newMovePoint[i * 3 - j].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); } for (int x = 0; x < mapsize; x++) { // 무브 포인트와 등대가 부딪히면 예외카운트 + 이말은 생성 안한다는 말임 for (int y = 0; y < mapsize; y++) { if (script.grid[x, y].worldPosition == MPpoisition) // 무브포인트와 일치할때 { if (script.grid[x, y].is_lighthouse == true) // 해당 위치가 등대일때 생성안함 { countL++; } else if (script.grid[x, y].is_trap == true) { // 해당 위치가 구멍일때 생성안하면서 view값 +1 view++; } } } } if (countL == 0) { if (MPpoisition.x > 0 && MPpoisition.y > 0) // 1사분면 { if (MPpoisition.x > over.x || MPpoisition.y > over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newMovePoint[i * 3 - j] = Instantiate(MovePointer); // 생성 newMovePoint[i * 3 - j].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); } } else if (MPpoisition.x > 0 && MPpoisition.y < 0) // 4사분면 { if (MPpoisition.x > over.x || MPpoisition.y < -over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newMovePoint[i * 3 - j] = Instantiate(MovePointer); // 생성 newMovePoint[i * 3 - j].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); } } else if (MPpoisition.x < 0 && MPpoisition.y > 0) // 2사분면 { if (MPpoisition.x < -over.x || MPpoisition.y > over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newMovePoint[i * 3 - j] = Instantiate(MovePointer); // 생성 newMovePoint[i * 3 - j].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); } } else if (MPpoisition.x < 0 && MPpoisition.y < 0) //3사분면 { if (MPpoisition.x < -over.x || MPpoisition.y < -over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newMovePoint[i * 3 - j] = Instantiate(MovePointer); // 생성 newMovePoint[i * 3 - j].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); } // 홀수맵에서는 좌표가 0일 수가 있음;; x,y가 하나이상 0인 경우임 } else if (MPpoisition.x == 0) { // x가 0일 경우 if (MPpoisition.y > 0) // 위쪽 { if (MPpoisition.y > over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newMovePoint[i * 3 - j] = Instantiate(MovePointer); // 생성 newMovePoint[i * 3 - j].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); } } else if (MPpoisition.y < 0) // 아래쪽 { if (MPpoisition.y < -over.y) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newMovePoint[i * 3 - j] = Instantiate(MovePointer); // 생성 newMovePoint[i * 3 - j].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); } } else { // 딱 중심일때 newMovePoint[i * 3 - j] = Instantiate(MovePointer); // 생성 newMovePoint[i * 3 - j].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); } } else if (MPpoisition.y == 0) { // y가 0일 경우 if (MPpoisition.x > 0) // 오른쪽 { if (MPpoisition.x > over.x) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newMovePoint[i * 3 - j] = Instantiate(MovePointer); // 생성 newMovePoint[i * 3 - j].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); } } else if (MPpoisition.x < 0) // 아래쪽 { if (MPpoisition.x < -over.x) { continue; // 맵 벗어나면 만들지 않는다. } else // 여기까지 왔으면 맵 안이라는 소리임 { newMovePoint[i * 3 - j] = Instantiate(MovePointer); // 생성 newMovePoint[i * 3 - j].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); } } else { // 딱 중심일때 newMovePoint[i * 3 - j] = Instantiate(MovePointer); // 생성 newMovePoint[i * 3 - j].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); } } else { newMovePoint[i * 3 - j] = Instantiate(MovePointer); // 생성 newMovePoint[i * 3 - j].transform.position = new Vector3(MPpoisition.x, MPpoisition.y); } } } } /* 플레이어 중심 8방위에 구멍 수 출력*/ PlayerRoundHoles.text = view + ""; }