본문 바로가기
Development/C#

[멋쟁이사자처럼 부트캠프 TIL 회고] Unity 게임 개발 3기 4일차

by Mobics 2024. 11. 22.

 

목차

    Unity

    어몽어스 캐릭터 만들기

    : Hierarchy의 Primitive Object를 활용하여 만들기 (Capsule, Cylinder, Cube 등)


    Material

    : Game Object가 입는 옷

    Material 생성 방법

    Material의 텍스쳐 종류

    - Albedo : Main(Color)

    - Metallic : 정반사

    - Smoothness : 난반사

    - Normal Map : 울퉁불퉁하게 만듦

    - Height Map : 빛의 깊이, 빛이 들어간 표현

    - Occlusion : 환경 차폐(OA)

    Game Object에 Material 적용

     

    ※ 여러 Game Object에 한꺼번에 적용

     

    ※ 적용했던 색을 원래대로 바꾸기

     

    Rendering Mode

    : 랜더링 모드에 따라 다양한 랜더링 가능

    - Opaque : 단단한 표면에 색상을 지닌 경우 사용되는 랜더링 모드 --> Alpha 값(투명도)을 무시하는 것, 대부분 사용

    - Cutout : 일부 빈 공간이 있는 경우 사용되는 랜더링 모드 --> 단단한 부위와 빈 공간이 섞인 경우 ex) 쇠창살, 창틀 등

    - Fade : 서서히 변하는 상태가 있는 랜더링 모드 ex) 파워업 아이콘 등

    - Transparent : 투명한 상태가 있는 랜더링 모드 --> Alpha 값을 적용한 것 ex) 창문의 유리창

    ※ 다 적용되는 Transparent가 좋은 것 아닌가? --> 최적화 문제 때문에 Opaque를 사용함


    Prefab

    : 월드에 존재하는 하나의 개체를 리소스 파일로 바꾸는 것

    ※ Scene = World, Asset = Resources

    Prefab하는 방법

    ※ Prefab이 됐다는 것은 원본 데이터 파일이 있다는 것

    Prefab된 것 수정하기

    : Project에서 더블 클릭하면 따로 수정 가능 --> Scene에 있는 모든 개체에 한꺼번에 적용됨

    ※ 다시 나올 땐 사진의 화살표 클릭

     

    ※ 한 개체만 수정한 것을 모든 Prefab한 것에 적용하기


    Unity C#

    접근제한자

    • public
    • private
    • protected

    SerializeField

    : 보안 수준은 유지하지만 Inspector에서 수정할 수 있는 기능

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class ExampleClass : MonoBehaviour
    {
        public int number1 = 10;
        private int number2 = 20;
    
        [SerializeField] private int number3 = 30;
        // 남들이 수정 못하지만, 에디터에서는 수정 가능한 보안 수준 설정
    }

    어몽어스 캐릭터 움직이기

    • GetKeyDown : 키를 누른 순간 1번 적용
    • GetKey : 키를 누르는 동안 계속 Loop
    • GetKeyUp : 키를 떼는 순간 1번 적용
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class CharacterMovement : MonoBehaviour
    {
        public float moveSpeed = 1f;
    
        void Update()
        {
            if (Input.GetKey(KeyCode.W))
                transform.position += Vector3.forward * moveSpeed;
            if (Input.GetKey(KeyCode.S))
                transform.position += Vector3.back * moveSpeed;
            if (Input.GetKey(KeyCode.A))
                transform.position += Vector3.left * moveSpeed;
            if (Input.GetKey(KeyCode.D))
                transform.position += Vector3.right * moveSpeed;
        }
    }

     

    ※ Unity에서 속도 조절하기


    Project 백업 방법

    1. Project View - Assets폴더 우클릭 - Show in Explorer 
    2. 프로젝트 파일 4개 압축

    Project 추가 방법

    1. 원하는 경로에 프로젝트 압축 풀기
    2. Unity Hub - Add - Add project from disk