feature/stage-hint-twinkle
Color FFE045

개인 씬 생성(이름 변경 YSA → StageLevel2)
스크립트 Hint 생성
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hint : MonoBehaviour
{
public Animator HintAnim;
private float _matchTimeout = 5f; //성공 매칭이 없는 시간
//private float _lastMatchTime = 0.0f; //마지막 매칭 시간
private bool isHint = false;
private GameManager _gameManager; //게임매니저에 접근하기 위한 변수
// Start is called before the first frame update
void Start()
{
_gameManager = FindObjectOfType<GameManager>(); //게임매니저 찾기
}
// Update is called once per frame
void Update()
{
float time = _gameManager.GetTime();
//_lastMatchTime = _gameManager.MatchedTime;
// CardCount가 변화하지 않은 경우
if (time - _gameManager.MatchedTime >= _matchTimeout && isHint == false)
{
//_iastCardCountChangeTime = Time.time;
isHint = true;
HintTwinkle();
}
}
void HintTwinkle()
{
int randomIdx = Random.Range(0, Board.CardObject.Count); // Board.CardObject 리스트의 인덱스 중 하나를 무작위로 선택
//현재 문제점 : 수가 1번 선택되는 것이 아닌, 25번 선택됨 or HintTwinkle() 25번 실행됨
Debug.Log(randomIdx);
//randomIdx 문제가 해결되면
//Board.CardObject _id
/* if(randomIdx == 2번째 선택된 것) {
해당 카드에 HintAnim.SetBool("isHint", true); 적용
} else {
2번째 선택된 것 다시 선택하기
}
*/
}
}
HintTwinkle() 실행 **public static CardInfo[] cardInfos** = { 배열 내용 };
**public static List<GameObject> CardObject = new List<GameObject>();**
void Start()
{
int cardAmount = BoardX * 6;
int numRows = 6;
float cardSpacing = 1.1f;
float cardYSpacing = 2.0f;
cardInfos = cardInfos.Skip(0).Take(cardAmount).ToArray();
cardInfos = cardInfos.OrderBy(x => Random.Range(0f, cardAmount / 2 - 1)).ToArray();
for (int i = 0; i < cardAmount; i++)
{
GameObject tempCard = Instantiate(Card, this.transform);
float x = (i % BoardX - (BoardX - 1) / 2.0f) * cardSpacing;
float y = (numRows / 2.0f - i / BoardX) * cardSpacing - cardYSpacing;
tempCard.transform.position = new Vector2(x, y);
tempCard.GetComponent<Card>().OnCardSetting(cardInfos[i]);
**CardObject.Add(tempCard);**
}
GameManager.Instance.CardCount = cardInfos.Length;
}
public float MatchedTime = 0.0f; //매칭된 시간 저장용
public void Matched()
{
_matchingCardCount++;
TeamName.SetActive(true); // 텍스트 UI 켜주기
if (FirstCard.Index == SecondCard.Index)
{
_audioSource.PlayOneShot(MatchClip);
FirstCard.OnDestroyCard();
SecondCard.OnDestroyCard();
CardCount -= 2;
TeamName.GetComponent<Text>().text = FirstCard.Name.ToString(); //켜준 텍스트 UI에 이미지에 맞는 팀원 이름 띄워주기
_cardMatchScore += 5;
if (CardCount == 0)
{
GameOver();
}
**//변수를 하나 만들어서 현재 time을 변수에 저장하고, 이 변수를 Hint 스크립트로 가져가기
MatchedTime = Time.time;**
}
else...
MatchedTime 생성Matched() 메소드에 매칭이 성공됐을 때 게임 시간을 MatchedTime 에 저장하는 부분 추가GameObject[] CardObject = {};
public static List<GameObject> CardObject = new List<GameObject>();
CardObject.Add(TempCard)
리스트 활용하기
Update의 if문이 문제인 것인지 HintTwinkle() 메소드 내용에 문제가 있는 것인지 확인 필요