69 lines
2.0 KiB
C#
69 lines
2.0 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class TileController : MonoBehaviour
|
|
{
|
|
public Vector2Int currentCoord;
|
|
public Vector2Int correctCoord;
|
|
public bool isFixed;
|
|
public GameObject lockIcon; // [신규] 인스펙터에서 연결할 변수
|
|
|
|
private SpriteRenderer sr;
|
|
private BoxCollider2D col; // 콜라이더 제어용
|
|
private int defaultSortingOrder = 0;
|
|
|
|
void Awake()
|
|
{
|
|
sr = GetComponent<SpriteRenderer>();
|
|
col = GetComponent<BoxCollider2D>();
|
|
defaultSortingOrder = sr.sortingOrder;
|
|
}
|
|
|
|
public void Initialize(Vector2Int coord, Color color, bool fixedTile)
|
|
{
|
|
this.currentCoord = coord;
|
|
this.correctCoord = coord;
|
|
this.isFixed = fixedTile;
|
|
sr.color = color;
|
|
|
|
if (lockIcon != null)
|
|
{
|
|
lockIcon.SetActive(fixedTile);
|
|
}
|
|
}
|
|
|
|
// 드래그 상태 변경 함수
|
|
public void SetDraggingState(bool isDragging)
|
|
{
|
|
if (isDragging)
|
|
{
|
|
// 1. 들었을 때: 제일 위에 보이게 하고, 크기 키우기
|
|
sr.sortingOrder = 100;
|
|
transform.localScale = Vector3.one * 1.1f; // 1.1배 확대
|
|
|
|
// 2. 중요: 레이캐스트가 내 뒤에 있는 타일을 감지할 수 있도록 내 콜라이더 끄기
|
|
col.enabled = false;
|
|
}
|
|
else
|
|
{
|
|
// 3. 놓았을 때: 원상복구
|
|
sr.sortingOrder = defaultSortingOrder;
|
|
transform.localScale = Vector3.one;
|
|
col.enabled = true;
|
|
}
|
|
}
|
|
|
|
// 이동 코루틴 (GameManager에서 호출)
|
|
public IEnumerator MoveToPosition(Vector3 targetPos, float duration)
|
|
{
|
|
Vector3 startPos = transform.position;
|
|
float time = 0;
|
|
while (time < duration)
|
|
{
|
|
transform.position = Vector3.Lerp(startPos, targetPos, time / duration);
|
|
time += Time.deltaTime;
|
|
yield return null;
|
|
}
|
|
transform.position = targetPos;
|
|
}
|
|
} |