
배열의 짝수 줄이 -1인 육각형 모양의 헥사곤 배열이었다.
배열인데.. 육각형이야..
- 헥사곤 모양을 만드는 방법
1) 기즈모

육각형 기즈모를 만들 수 있대서 함 해봤는데 문제가 2개 있다.
1: 신뷰에서만 보이고 게임뷰에서는 안보인다. >> 게임 뷰에서 보이는 방법있음
2: 짝수 줄 구슬의 시작점이 구슬 크기*0.5 만큼 들여쓰기로 엇갈리게 그려져야 함. 이건 연습 삼아 가로 세로로 그어봄
using UnityEngine;
public class HorizontalDividerGizmo : MonoBehaviour
{
int numberOfDivisions = 8; // 가로로 나눌 분할 수
float screenWidth = 5.62f; // 화면 가로 너비
float screenHeight = 10f; // 화면 세로 길이
float XStart = -2.45f; // 가로 시작 위치
float YStart = -5.3f; // 세로 시작 위치
int numberOfVertical = 13;
void OnDrawGizmos()
{
// 가로 분할 선
Gizmos.color = Color.yellow; // 기즈모 색상
float divisionWidth = screenWidth / numberOfDivisions; // 가로 분할 섹션의 너비
for (int i = 0; i <= numberOfDivisions; i++)
{
// 선의 시작과 끝 좌표 계산
Vector3 start = new Vector3(i * divisionWidth + XStart, YStart, 0);
Vector3 end = new Vector3(i * divisionWidth + XStart, screenHeight + YStart, 0);
Gizmos.DrawLine(start, end); // 기즈모 라인 그리기
}
// 세로 분할 선
Gizmos.color = Color.red; // 기즈모 색상
float divisionLength = screenHeight / numberOfVertical; // 세로 분할 섹션의 너비
for (int i = 0; i <= numberOfVertical; i++)
{
Vector3 start = new Vector3(XStart, i * divisionLength + YStart, 0);
Vector3 end = new Vector3(XStart+ screenWidth, i * divisionLength + YStart, 0);
Gizmos.DrawLine(start, end); // 기즈모 라인 그리기
}
}
}
2) 라인랜더러

이거는 플레이 할 때만 볼 수 있다. 이래서 안쓰는 거군.
중심점을 기준으로 끝에서 60도 각도로 꺽는 걸 6번 반복해 라인을 그려서~ 시작점에 닿게 함
using UnityEngine;
public class HexagonRenderer : MonoBehaviour
{
private LineRenderer lineRenderer;
float radius = 0.35f; // 육각형의 반지름
int numberOfHexagons = 8; // 생성할 육각형의 개수
float screenHeight = 10f; // 화면 세로 길이
float lineWidth = 0.1f; // 라인의 두께
void Start()
{
lineRenderer = GetComponent<LineRenderer>();
lineRenderer.positionCount = numberOfHexagons * 7; // 각 육각형당 6개의 점 + 1점(시작점)
// 라인 두께 설정
lineRenderer.startWidth = lineWidth;
lineRenderer.endWidth = lineWidth;
DrawHexagons();
}
void DrawHexagons()
{
float hexWidth = radius * 2; // 육각형의 너비
float hexHeight = Mathf.Sqrt(3) * radius; // 육각형의 높이
float startX = -2.1f; // 시작 X 좌표
float startY = -4.85f; // 시작 Y 좌표
for (int h = 0; h < numberOfHexagons; h++)
{
float xOffset = startX + h * hexWidth; // 각 육각형의 X 위치
for (int i = 0; i < 7; i++)
{
float angle = (i * 60 + 30) * Mathf.Deg2Rad; // 60도 간격으로 각도 계산하고 30도를 추가하여 꼭지점이 위로 가도록 함
float x = xOffset + radius * Mathf.Cos(angle); // X 좌표 계산
float y = startY + radius * Mathf.Sin(angle); // Y 좌표 계산 (Y 시작 위치를 적용)
lineRenderer.SetPosition(h * 7 + i, new Vector3(x, y, 0)); // 점 위치 설정
}
}
// 선을 연결하기
for (int h = 0; h < numberOfHexagons; h++)
{
lineRenderer.SetPosition(h * 7 + 6, lineRenderer.GetPosition(h * 7)); // 마지막 점을 시작점에 연결
}
}
}
3) 메쉬랜더러 담에
>> 중요한 건 육각형 모양을 만드는 것이 아니라!
1. 버블 사이가 최대한 틈이 없이 붙어있게 하는 모양이 육각형
2. 시작 지점에 오프셋 값을 넣어 배열을 엇갈린 모양으로 출력하는 것!!
- Bubble
- 스타트에 크기 줄이기 ㄴㄴ >> 스프라이트에서 크기 줄이기 ㅇㅇ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bubble : MonoBehaviour
{
Transform Transform;
void Awake()
{
Transform = GetComponent<Transform>();
this.transform.localScale = new Vector3(0.65f, 0.65f, 0.65f);
}
}

'개발일지 > Puzzle Bubble' 카테고리의 다른 글
구슬 배치 색 랜덤 변경 (0) | 2024.10.13 |
---|---|
버블 배열 위에 좌표 찍기 (1) | 2024.10.12 |