대외활동/starters 부트캠프 feat.웅진씽크빅
유데미 스타터스 취업 부트캠프 유니티 1기 15주차 학습 일지
Heeyeon Choi
2022. 10. 2. 23:41
728x90
728x90
cinemachine 사용하기
플레이어가 무당이에 탑승 시,
- 플레이어가 무당이를 탑승할지 선택하는 ‘예/아니오’ 판넬 없애기
- 플레이어 중심으로 움직이던 카메라를 무당이로 옮기기
- 방향키 조작 시 무당이가 움직이도록 설정하기
- 무당이의 ‘Rigidbody 2D’ Freeze position이 z축 제외한, x,y축 이 unchecked 되면서 움직일 수 있도록 하기
- (부가 요소) 효과음 넣기
- 무당이에서 내릴 수 있는 버튼 표시하기
- <TalkManager.cs>
//선언부에 넣어주기
public GameObject talkPanel3; // 무당이 예/ 아니오 판넬
public GameObject mudang; //mudang 오브젝트
public GameObject mudangQuest; // 무당이 내릴때 누르는 버튼
//Awake()에서 mudang이의 rigidbody 요소 넣어주기
void Awake()
{
talkName = new Dictionary<int, string[]>();
rb = mudang.GetComponent<Rigidbody2D>();
audioSource = this.GetComponent<AudioSource>();
talkData = new Dictionary<int, string[]>(); //대화에 문장이 여러개 존재
portraitData = new Dictionary<int, Sprite>();
GenerateData();
}
//무당이를 탈 것인지 안 탈 것인지 물어보는 함수
public void SelectTalk(string type){
var heemudangAction = mudang.GetComponent<heeMudangAction>();
var heeobjectdata = mudang.GetComponent<heeObjectData>();
Vector3 pos;
pos = this.mudang.transform.position;
switch(type){
case "y":
audioSource.clip = audioClip;
audioSource.loop = false;
audioSource.Play();
talkPanel3.SetActive(false);
mudangQuest.SetActive(true);
newStu.SetActive(false);
gameManager.SetCameraTarget(mudang);
heemudangAction.enabled = true;
heeobjectdata.id = 12345;
heeobjectdata.enabled= false;
rb.constraints = RigidbodyConstraints2D.None;
rb.constraints = RigidbodyConstraints2D.FreezeRotation;
talkText3.text += "\\n무당이에서 내리고 싶을 때 상단 초록색 버튼을 클릭하면 됩니다.";
break;
case "n":
talkPanel3.SetActive(false);
break;
}
}
플레이어가 무당이에서 하차 시,
- 플레이어를 등장시키기
- 플레이어의 포지션을 무당이 근처로 설정하기
- 무당이에서 내리는 버튼을 보이지 않게 하기
- 카메라를 플레이어 중심으로 옮기기
- 무당이의 RigidbodyConstraints2D를 모두 Freeze하기
- <gameManager.cs>
//선언부에 변수 선언
public GameObject cmVcam; // cm카메라 오브젝트
public GameObject heenewStu; //newStu 오브젝트
public GameObject heemudang; //mudang 오브젝트
public GameObject heetalkPanel3; // 무당이 예/ 아니오 판넬
private Rigidbody2D rb2;
void Awake() {
cmCamera = cmVcam.GetComponent<CinemachineVirtualCamera>();
rb2 = heemudang.GetComponent<Rigidbody2D>();
Debug.Log(questManager.CheckQuest());
}
//마우스 클릭시 무당이를 내림
public void noneMudang(){
var heemudangAction = heemudang.GetComponent<heeMudangAction>();
Vector3 pos2;
pos2 = this.heemudang.transform.position;
mudangDown.SetActive(false);
heetalkPanel3.SetActive(false);
var heeobjectdata = heemudang.GetComponent<heeObjectData>();
heeobjectdata.enabled= true;
heeobjectdata.id=3000;
heenewStu.SetActive(true);
SetCameraTarget(heenewStu);
heemudangAction.enabled = false;
heemudangAction.MudangBorderline.SetActive(false);
heemudangAction.controlKey.SetActive(true);
rb2.constraints = RigidbodyConstraints2D.FreezeAll;
heenewStu.transform.position = new Vector3(pos2.x+1,pos2.y+1, 0);
}
//카메라를 위한 스크립트
public void SetCameraTarget(GameObject followTarget)
{
if(cmCamera == null)
{
Debug.Log("cmCamera is null");
}
if(followTarget == null) Debug.Log("followTarget is null");
cmCamera.Follow = followTarget.transform;
cmCamera.LookAt = followTarget.transform;
}
——————————————————————————
유데미코리아 바로가기 : https://bit.ly/3b8JGeD
본 포스팅은 유데미-웅진씽크빅 취업 부트캠프 유니티 1기 과정 후기로 작성되었습니다.
728x90