[개발일지] 나폴리탄스파게티 20230610
2023. 6. 10. 11:28ㆍ2학년 1학기 프로젝트
화장실 물소리 이벤트
(미완성) 물이 떨어지는 소리가 들린다면 화장실에서부터 이어지는 액체를 따라 이동하고 삐뚤어진 액자를 올바르게 정리하도록 함
이벤트가 진행되면 액자의 각도가 틀어지도록 함
public class WaterSoundEvent : MonoBehaviour
{
// 이벤트 진행 변수
public bool event6 = false;
Transform transform;
void Start()
{
transform = GetComponent<Transform>();
}
void Update()
{
if(event6 == true)
{
Event(); // 이벤트 매니저를 통한 이벤트 진행
}
// E키를 누를 경우 그림이 원래대로 돌아옴 (임시)
if(Input.GetKeyDown("e"))
{
Original();
}
}
// 물이 떨어지는 소리 재생
void PlaySound()
{
}
// 액자 이벤트
void Event()
{
// 액자가 삐뚤어지도록 함
gameObject.transform.rotation = Quaternion.Euler(0, 0, 20);
// 액자로 연결되는 액체 생성
}
// 액자가 원래대로 돌아오도록 함
void Original()
{
gameObject.transform.rotation = Quaternion.Euler(0, 0, 0);
event6 = false; // 이벤트 종료
}
}
창문 이벤트 구현
창문이 보인다면 밖을 보아서는 안 되고, 밖으로 나가서도 안됨 (05시 ~ 06시 사이 등장 이벤트)
만약 1분(게임상 시간)내에 창문으로 도달하지 못 할 경우 창문은 사라짐
(수정) 또한 창문을 통해 밖으로 나갈 경우 화면이 하얀색으로 변하고 엔딩 텍스트가 뜨며 엔딩
화면 및 텍스트가 나타날 때 페이드인 효과 구현
public class WindowEventController : MonoBehaviour
{
public bool event9 = false; //이벤트를 진행할지 결정할 변수
public GameObject window; // 창문 오브젝트를 담을 변수
int time = 60; // 카운트 다운에 쓰일 변수 -> 흐른 시간 체크할 변수
void Start()
{
window.SetActive(false);
}
void Update()
{
// 이벤트가 시작될 경우,
if(event9 == true)
{
// 창문 나타남
window.SetActive(true);
// 카운트 다운 시작
StartCoroutine(CountDown());
}
}
// 카운트다운
IEnumerator CountDown()
{
while(time > 0)
{
time--;
Debug.Log(a);
yield return new WaitForSeconds(1.0f);
}
// 카운트다운이 끝날경우 창문이 사라짐
window.SetActive(false);
}
}
public class WindowEvent : MonoBehaviour
{
public GameObject whiteScreenObj; // 흰 색 화면 UI Object
public Text endingText; // 엔딩시 나타날 Text
Image whiteImage; // 화면의 Image Component를 받아올 변수
Text text; // EndingText의 Text Component를 받아올 변수
Color colorScreen = Color.white; // 색상 결정
void Start()
{
whiteImage = whiteScreenObj.GetComponent<Image>();
text = endingText.GetComponent<Text>();
colorScreen.a = 0f; // 투명한 상태로 시작
text.color = new Color(text.color.r, text.color.g, text.color.b, 0); // 투명한 상태로 시작
}
// 충돌 체크
void OnTriggerEnter(Collider collision)
{
StartCoroutine(FadeIn());
}
// 서서히 흰색 화면이 나타나는 효과
IEnumerator FadeIn()
{
while(colorScreen.a < 1.0f)
{
colorScreen.a += Time.deltaTime * 0.5f;
whiteImage.color = colorScreen;
yield return null;
}
// 화면이 하얗게 변한 이후 엔딩텍스트 나타남
StartCoroutine(FadeInText());
}
// 서서히 엔딩텍스트가 나타나는 효과
IEnumerator FadeInText()
{
text.color = new Color(text.color.r, text.color.g, text.color.b, 0);
while(text.color.a < 1.0f)
{
text.color = new Color(text.color.r, text.color.g, text.color.b, text.color.a + (Time.deltaTime * 0.3f));
yield return null;
}
}
}
게임상의 시간 구현
실제 5초가 게임상 시간으로는 1분
이를 UI통해 나타냄
(수정) 페이즈를 제거하여 시간이 일정하게 흐르도록 수정됨
public class TimeController : MonoBehaviour
{
float gameTime = 5.0f; //게임상의 시간을 계산(실제 5초마다 게임 속 1분이 흐름)
float updateTime; //게임상 시간을 계산하기 위해 실제 시간 데이터를 담은 변수
public int timeHour; //시
public int timeMinute; //분
public Text timeText; //시간을 나타내는 Text UI변수
void Start()
{
// 시작시 시각 00:00
timeText.text = (timeHour.ToString("00") +" : "+ timeMinute.ToString("00"));
}
void Update()
{
// 시간 계산 및 Text UI로 띄우기
if(updateTime > gameTime)
{
updateTime = 0.0f;
timeMinute ++;
if(timeMinute > 59)
{
timeHour ++;
timeMinute = 0;
}
// 00:00형태로 시간을 나타냄
timeText.text = (timeHour.ToString("00") +" : "+ timeMinute.ToString("00"));
}
else
{
updateTime += Time.deltaTime;
}
}
}
이벤트 매니저
(수정) 다른 이벤트 스크립트에서 이벤트가 완료되었을 경우 이벤트 매니저에서 완료 정보를 받음
외에도 추가적으로 수정함
public class EventManager : MonoBehaviour
{
// 외부 스크립트 및 오브젝트
public GameObject[] events;
TimeController timeCtrl; // 0
// 1
PaintBloodEventController bloodPaintEventCtrl; // 2
PaintEvent paintEventCtrl; // 3
// 4
CCTVcontroller cctvCtrl; // 5
WaterSoundEvent waterSoundEvent; // 6
// 7
LightController lightController;// 8
WindowEventController windowEventCtrl; // 9
TruthEvent truthEvent; // 10
// 랜덤 시스템 관련 변수
public int nowEvent; // 현재 진행중인 이벤트 개수를 담을 변수
public int typeEventNum; // 진행 확정된 이벤트 종류 정보를 담을 변수
int randomEventNum; // 확정되지 않은 이벤트 종류를 랜덤으로 담을 변수
int isEvent; // 이벤트를 진행할지 하지않을지 결정하는 값을 담을 변수
int indexCompleteEvent; // 리스트 내에서 인덱스 값을 확인할 변수
int maxEvent = 1;
bool isThere; // 중복값 확인할 변수
int phase;
List<int> TypeEventList = new List<int>(); // 현재 진행중인 이벤트 정보를 담을 리스트
void Start()
{
RandomEvent();
// 각 컴포넌트 받아오기
timeCtrl = events[0].GetComponent<TimeController>(); // 0
bloodPaintEventCtrl = events[2].GetComponent<PaintBloodEventController>(); // 2
paintEventCtrl = events[3].GetComponent<PaintEvent>(); // 3
cctvCtrl = events[5].GetComponent<CCTVcontroller>(); // 5
//6
//8
windowEventCtrl = events[9].GetComponent<WindowEventController>(); // 9
// 10
}
void Update()
{
// 02:00 ~ 04:00 이벤트 6이하
if(timeCtrl.timeHour >= 2)
{
maxEvent = 6;
}
// 04:00 ~ 05:00 이벤트 8이하
if(timeCtrl.timeHour >= 4)
{
maxEvent = 8;
}
// 게임상 시각이 05:00일 경우 windowEvent를 진행할지 랜덤하게 결정
if(timeCtrl.timeHour >= 5)
{
Invoke("RandomEventWindow", 10);
}
// 이벤트 완료시
if(bloodPaintEventCtrl.event2 == false)
CompleteEvent(2);
if(paintEventCtrl.event3 == false)
CompleteEvent(3);
if(cctvCtrl.event5 == false)
CompleteEvent(5);
if(waterSoundEvent.event6 == false)
CompleteEvent(6);
if(windowEventCtrl.event9 == false)
CompleteEvent(9);
}
// Event를 진행할지 랜덤하게 결정하는 메서드
void RandomEvent()
{
isEvent = Random.Range(0, 2); // 0, 1 (0: 진행X / 1: 진행O)
// 이벤트 종류 추첨
if(isEvent == 1)
{
Debug.Log("진행할 이벤트 종류 추첨");
randomEventNum = Random.Range(1, 8); // 1~7번 이벤트 결정
isThere = TypeEventList.Contains(randomEventNum); // 진행중인 이벤트 중 중복되는 이벤트가 있는지 확인
// 기존에 진행중인 이벤트 중 중복된 값이 없을 때 진행
if(isThere == false)
{
typeEventNum = randomEventNum; // 이벤트 진행 확정
goEvent(randomEventNum);
nowEvent++; // 현재 진행중인 이벤트 개수 추가
TypeEventList.Add(typeEventNum); // 진행 이벤트 정보 저장
}
// 진행중인 이벤트 Debug.Log (확인용)
foreach(int a in TypeEventList)
{
Debug.Log(a);
}
}
// 최대 진행 이벤트 개수보다 적을 때 계속해서 뽑기 진행
if(nowEvent < maxEvent)
{
Invoke("RandomEvent", 20);
}
}
void RandomEventWindow()
{
// 이벤트 진행 될 확률 낮게
int random = Random.Range(0, 4);
if(random == 1)
{
Debug.Log(random);
windowEventCtrl.event9 = true;
}
else
{
Invoke("RandomEventWindow", 10);
}
}
// 이벤트가 완료될 경우 list에 담긴 이벤트 정보 삭제
void CompleteEvent(int completeEvent)
{
// List에 저장된 이벤트 종류가 몇번에 저장되어있는지 찾아줌
indexCompleteEvent = TypeEventList.IndexOf(completeEvent);
// 완료된 이벤트 정보 제거
TypeEventList.RemoveAt(indexCompleteEvent);
// 진행중인 이벤트 Debug.Log
foreach(int a in TypeEventList)
{
Debug.Log(a);
}
}
// 이벤트를 진행 변수를 True로 바꾸어 활성화함
void goEvent(int eventNum)
{
switch(eventNum)
{
case 1:
Debug.Log("test1");
break;
case 2:
bloodPaintEventCtrl.event2 = true;
break;
case 3:
paintEventCtrl.event3 = true;
break;
case 4:
Debug.Log("test4");
break;
case 5:
cctvCtrl.event5 = true;
break;
case 6:
waterSoundEvent.event6 = true;
break;
case 7:
Debug.Log("test7");
break;
case 8:
Debug.Log("test7");
break;
case 9:
windowEventCtrl.event9 = true;
break;
case 10:
Debug.Log("test7");
break;
}
}
}
'2학년 1학기 프로젝트' 카테고리의 다른 글
[개발일지] 나폴리탄 스파게티 20230612 ~ 20230617 (0) | 2023.06.23 |
---|---|
[개발일지] 나폴리탄 스파게티 20230611 (0) | 2023.06.11 |
[개발일지] 나폴리탄스파게티 20230608 (0) | 2023.06.10 |
[개발일지] 나폴리탄스파게티 20230607 (0) | 2023.06.09 |
[개발일지] 나폴리탄스파게티 20230602 (0) | 2023.06.09 |