오늘 한 일
- Status 수치 업데이트
이건 전의 것과 동일 하지만 Json을 통하여 값을 받아와 리펙토링 하였지만 크게 바뀐것은 없기에 다음으로 넘어가겠습니다.
- NPC구현, 맵 추가, 인트로 구현
NPC구현이 필요한 이유 먼저 보겠습니다.
저희 스토리는 플레이어가 배에서 난파되어 해안가에 떠밀려온 숲의 정령
NPC가 플레이어를 구조해주면서 시작이 됩니다.
그렇기 때문에 제가 생각한 바로는 Intro부분을 추가하면 좋겠다고 생각해서 기본 장로 NPC와 플레이어를 배치할 맵을 새로 배치하고 있었습니다.
그래서 설계(구조)를 어떻게 짜보면 좋을지 생각해봤습니다.
-> 시작을 하면 플레이어가 배에 난파된 상황이기 때문에 카메라를 옆으로 눕히면서 눈에 깜빡임을 추가
->NPC가 점점 다가오며 혼잣말을 하는 대화를 추가
여기서 SFX로 갈매기 소리와 파도 부딪히는 소리가 더 추가가 된다면
연출효과는 나쁘지 않을것이라 판단이 되었습니다.
IntroScene에서 GameScene로 넘어갈거기 때문에 Intro에 Player는 스크립트를 다 빼주었습니다.
(굳이 Input Action을 넣어서 할 필요가 없음. 그냥 씬 전환 할거이기 때문에 더미만 남겨두는 느낌)
플레이어는 그냥 추가해서 오른쪽으로 눞히기 위해 Rotation값의 x를 -90으로 수정해주었습니다.
그리고 IntroCamera를 추가해서 IntroCameraController.cs를 만들어서 붙여줍니다.
그리고 새로운 Canvas를 추가해서 Eye Blink Controller.cs를 만들어서 붙여줍니다.
- EyeBlinkController.cs
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class EyeBlinkController : MonoBehaviour
{
public Image eyeImage;
void Start()
{
StartCoroutine(BlinkRoutine());
}
IEnumerator BlinkRoutine()
{
// 완전 감김
SetAlpha(1f);
yield return new WaitForSeconds(1.5f);
// 깜빡 2~3회
yield return Blink();
yield return Blink();
// 완전히 눈 뜸
yield return Fade(1f, 0f, 2f);
gameObject.SetActive(false);
}
IEnumerator Blink()
{
yield return Fade(1f, 0.3f, 1f);
yield return new WaitForSeconds(0.3f);
yield return Fade(0.3f, 1f, 2f);
yield return new WaitForSeconds(1f);
}
IEnumerator Fade(float from, float to, float time)
{
float t = 0;
while (t < time)
{
t += Time.deltaTime;
SetAlpha(Mathf.Lerp(from, to, t / time));
yield return null;
}
}
void SetAlpha(float a)
{
var c = eyeImage.color;
eyeImage.color = new Color(c.r, c.g, c.b, a);
}
}
//기본적으로 눈 깜빡임을 주기 위해서는 실행하고 다른거 실행하고 기다리는게 필요합니다. 그렇기에 코루틴을 만들어서
이 기능을 작동 가능하게 해주었습니다.
- IntroCameraController
using UnityEngine;
using System.Collections;
public class IntroCameraController : MonoBehaviour
{
public Transform lookTarget;
private Quaternion startRot;
private Quaternion normalRot;
void Start()
{
startRot = transform.rotation;
normalRot = Quaternion.Euler(5, 0, 0);
StartCoroutine(RecoverView());
}
IEnumerator RecoverView()
{
// 눈 거의 다 뜬 뒤
yield return new WaitForSeconds(6.5f);
Quaternion lookRot =
Quaternion.LookRotation(
(lookTarget.position - transform.position).normalized
);
// NPC를 바라보되, 위를 보도록 X축 보정
Vector3 euler = lookRot.eulerAngles;
euler.x -= 10f; // 위를 보게
lookRot = Quaternion.Euler(euler);
// NPC 쪽으로 회전
yield return Rotate(startRot, lookRot, 2.5f);
yield return new WaitForSeconds(2.0f);
// 다시 원래 시야로
yield return Rotate(lookRot, startRot, 3.0f);
}
IEnumerator Rotate(Quaternion from, Quaternion to, float duration)
{
float t = 0f;
while (t < duration)
{
t += Time.deltaTime;
transform.rotation = Quaternion.Slerp(from, to, t / duration);
yield return null;
}
}
}
이 2개가 결합이 되어 눈 깜빡임 효과를 주었습니다. 이제 추가해 볼 사항은
눈 모양을 Mask를 추가해서 좀 더 모양을 집중하고,
마지막에 눈 깜빡임 효과를 더 주어 일어나기 전에 행동 한 개가 더 추가되면 좋겠습니다. 오늘은 여기까지.. 맵을 만들고 있기 떄문에 이상 입니다!