//게임개발 종합반 - 4주차(스파르타코딩클럽)
보드 게임 특징
만들 순서
순서만 명확히 해도 머릿속에, 그리고 코드 상에 구체화가 쉬워진다.
- 기본 씬 구성하기 : 배경, 타이머, 리소스 받아두기
- 시간 보내기
- 카드 깔기
- 카드 뒤집기 애니메이션 만들기
- 같은 카드을 뒤집었을 때 없애기
카드 만들기
- cards(Create Empty) 에 card(Create Empty) 들이 들어가는 형태로 구현
- card 의 앞 뒤는 sprite로 구현(sprite Renderer 컴포넌트를 기본 탑재) - sprite에 이미지 할당
이미지 크기 조절
뒷면에 Text 넣기
- Canvas 를 World Space로 변경
- 위치에 맞게 Alignment, Scale 등 조정
gameManager 생성
public class gameManager : MonoBehaviour
{
public Text timeTxt;
float time;
void Update()
{
time += Time.deltaTime;
timeTxt.text = time.ToString("N2");
}
}
자동으로 카드 생성 하기
for 문으로 구현하기
- card 가 cards안에 생기도록 parent지정
public class gameManager : MonoBehaviour
{
public Text timeTxt;
float time;
public GameObject card;
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < 16; i++)
{
GameObject newCard = Instantiate(card);
//newCard를 Cards안으로 넣기
newCard.transform.parent = GameObject.Find("cards").transform;
}
}
float x = (i / 4) * 1.4f - 2.1f;
float y = (i % 4) * 1.4f - 3.0f;
newCard.transform.position = new Vector3(x, y, 0);