TIL 3
카드 맞추기 게임이 틀릴때마다 시간이 감소하고 주어진 시간이 짧아 게임에 불합리함을 느꼈기에 3초간 보여주고 시작하는 기능을 넣었다 처음엔 게임 매니저에서 카드 배치 하는 부분에서 카드의 트랜스폼을 변화시키려 해보았지만 실패하였다 이부분에 꾀나 애를 먹었는데 생각해보니 카드가 변화하는것이니 카드에서 변화시키면 좋겠다는 생각에 카드.CS에서 구현을 시도 하였고 성공하였다.
CARD@@@@
public void open() //오픈 처음에 보여주기
{
currentStage = gameManager.I.currentStage; // 스테이지를 받은후 스테이지에 따라 크기조절
if (currentStage ==0)
{
anim.SetBool("isOpen1", true);
}
else if (currentStage == 1)
{
anim.SetBool("isOpen2", true);
}
else if (currentStage >=2)
{
anim.SetBool("isOpen3", true);
}
gameManager.I.timeTxtObject.SetActive(false); //시작전이기에 타임텍스트를 숨겨줌
transform.Find("front").gameObject.SetActive(true); // 앞면 가시화
transform.Find("back").gameObject.SetActive(false); // 뒷면 비가시화
Invoke("closed", 3f); //3초간 보여주기에 3초후 닫기
}
public void closed() // 클로즈 보여준후 다시 닫기
{
if (currentStage == 0) // 오픈처럼 스테이지에 따라서 닫아준다
{
anim.SetBool("isOpen1", false);
}
else if (currentStage == 1)
{
anim.SetBool("isOpen2", false);
}
else if (currentStage >= 2)
{
anim.SetBool("isOpen3", false);
}
transform.Find("back").gameObject.SetActive(true); // 뒷면 가시화
transform.Find("front").gameObject.SetActive(false); // 앞면 비가시화
gameManager.I.time = 30f; //처음엔 타임스케일0 만들고 3초후 보여주기로 만들었었는데 이경우 타임 스케일이 0초이기 때문에 3초후 까지 시간이 지나지 않았다 즉 지금도 시간은 감소중이고 다보여준후 다시 시간을 30초로 만들어주었다 아마 스테이지를 늘린다면 이것도 변수로 받아서 스테이지 별로 구별해줄듯 하다
gameManager.I.timeTxtObject.SetActive(true); // 시작하였기에 남은 게임시간을 다시보여줌
}
COUNT321@@@@
생성할때 게임오브젝트에선 이름을 321카운트로 만들었는데 스크립트에선 숫자로 시작할수 없기에 카운트321이되었다
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.SocialPlatforms.Impl;
using UnityEngine.UI;
public class count321 : MonoBehaviour
{
public float time = 3; //3초간 보여주기
public Text count3;
public AudioSource audioSource;
public AudioClip start; // 띠 띠 띠 를 3 2 1 타이밍에
// Start is called before the first frame update
void Start()
{
startSound();
time = 3f;
}
// Update is called once per frame
void Update()
{
time -= Time.deltaTime;
count3.text = time.ToString("N0");
if (time <= 0.01f) // 처음엔 == 0 으로 했는데 사라지지 않았었다 디스트로이로 파괴하지 못한줄 알았으나 시간이 0.0000000000 .... 에 정확히 멈춰야지만 파괴되기에 -1 -2 이런식으로 계속 나타났으나 이하로 바꿔서 해결 유니티 면에서 화면 중앙으로 위치를 이동시켰으나 검은색 사진이 중앙에 위치할경우 가시성이 좀 떨어지는 문제가 있으나 큰 지장은 없어 그대로 유지하고 있다
{
Destroy(gameObject);
}
}
void oneshot()
{
audioSource.PlayOneShot(start, 0.5f);
}
void startSound()
{
Invoke("oneshot", 0f); // 3 2 1 스타트를 넣고 싶었으나 스타트 음성을 구하지못했다 아쉬운 부분
Invoke("oneshot", 1f);
Invoke("oneshot", 2f);
}
}
perpectGame@@@@@@@@@@@@@
게임 매니저에 들어가있다. 만들다보니 생각보다 정이붙어 이런 기능이 있으면 좋겠다는 생각으로 추가했다
스테이지랑 매칭횟수로 1번도 틀린적이 없는지 구별하여 만약 1번도 틀리지않았다면 점수를 2배시켜준다.
public void PerpectGame()
{
if (currentStage == 0 && attempts==1)
{
score *= 2;
perpectPanel.SetActive(true);
}
else if (currentStage == 1 && attempts == 3)
{
score *= 2;
perpectPanel.SetActive(true);
}
else if (currentStage >= 2 && attempts == 7)
{
score *= 2;
perpectPanel.SetActive(true);
}
perpect = false;
}