Tag: 오브젝트를 구분하는 단순한 문자열

Material 속성

- Emission: 빛냄

Collider 속성

- isTrigger: 물리적으로 맞닿는 것이 아니면 체크

GameManager 오브젝트

- Create Empty로 오브젝트 생성 -> 이름 GameManager 지정 (통상 만들어 사용하는 오브젝트)

- 형태가 없고 전반적인 로직을 가진 오브젝트

기타

- Find 계열 함수 사용 지양 (부하를 초래할 수 있으므로 피하는 것을 권장)

- Find 사용해서 찾지말고, 직접 오브젝트를 설정 (public GameManagerLogic manager)

 

< PlayerBall.cs >

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerBall : MonoBehaviour
{
    public float jumpPower = 30;
    public int itemCount;
    bool isJump;
    Rigidbody rigid;

    AudioSource audioSource;

    void Awake()
    {
        isJump = false;
        rigid = GetComponent<Rigidbody>();
        audioSource = GetComponent<AudioSource>();
    }

    void Update()
    {
        if (Input.GetButtonDown("Jump") && !isJump) {
            isJump = true;
            rigid.AddForce(new Vector3(0, jumpPower, 0), ForceMode.Impulse);
        }
    }

    void FixedUpdate()
    {
        float h = Input.GetAxisRaw("Horizontal");
        float v = Input.GetAxisRaw("Vertical");
        rigid.AddForce(new Vector3(h, 0, v), ForceMode.Impulse);
    }

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Floor")
        {
            isJump = false;
        }
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Item") {
            itemCount++;
            audioSource.Play();
            other.gameObject.SetActive(false);
        }
    }
}

< ItemCan.cs >

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemCan : MonoBehaviour
{
    public float rotateSpeed;

    // Update is called once per frame
    void Update()
    {
        transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime, Space.World);
    }
}

#4 카메라가 공 따라가기

OnLateUpdate(): 카메라같이 뒤에 따라 붙는 업데이트

< CameraMove.cs >

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraMove : MonoBehaviour
{
    Transform playerTransform;
    Vector3 offset;

    void Awake()
    {
        playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
        offset = transform.position - playerTransform.position;
    }

    
    void LateUpdate()
    {
        transform.position = playerTransform.position + offset;
    }
}

#5 결승점

Cylinder 생성

Material 적용

Point로 이름 변경

tag로 Finish 설정

 

#6 장면이동

using UnityEngine.SceneManagement;

- SceneManager: 장면을 관리하는 기본 클래스

- SceneManager.LoadScene(): 주어진 장면을 불러오는 함수

 

Stage를 나누기위해  Scene 추가 생성

- Scene 생성 (File-> New Scene)

- Scene 추가 (File -> Build Settings -> Add Open Scenes)

 

#6.1 떨어졌을 때 재시작

GameManager에 BoxCollider 추가

- BoxCollider의 Size를 X100, Y100으로 크게 설정

 

#7 스테이지

기존 Floor 체크 Off

3D 오브젝트 Cube 생성

 

#8 UI

UI -> Image 생성

상당 2D를 눌러 작업

Image

- Source Image 지정, 색상 지정

- Anchor를 Left Top으로 지정 

- Pivot X0, Y1 지정

 

Canvas 하위로 Text 생성

- Anchor를 Left Top으로 지정 

- Pivot X0, Y1 지정

- Arial, Bold, Size 50

 

< GameManagerLogic.cs >

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class GameManagerLogic : MonoBehaviour
{
    public int totalItemCount;
    public int stage;
    public Text stageCountText;// add
    public Text playerCountText;// add

    void Awake()
    {
        stageCountText.text = "/ " + totalItemCount;// add
    }

    public void OnPlayerItem(int count)// add
    {
        Debug.Log("OnPlayerItem() " + count);
        playerCountText.text = count.ToString();
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            SceneManager.LoadScene(stage);
            //SceneManagement.LoadScene("stage1_" + stage);
        }
    }
}

 

재질만들기

- 디폴트 재질은 편집이 안됨

- Create -> Material

- 색상: 청록

- Metallic: 메탈

- Smoothness: 빛 반사

- 이미지: 텍스처

 

 

 

 

 

참고 블로그

- [Unity]기초 3D게임 만들기-1 (tistory.com)

 

[Unity]기초 3D게임 만들기-1

[유니티 기초 예제 - BE1] 기초만 꾹꾹 눌러담은 3D 게임 만들기 : 골드메탈 님의 영상을 보고 쓰여진 게시글입니다. 이번게시글에선 플레이어 만들기 아이템 만들기 플레이어와 아이템의 상호작

iagreebut.tistory.com

팔로업 동영상

- https://www.youtube.com/watch?v=pTc1dakebow&t=44s

 

'게임엔진 > 유니티' 카테고리의 다른 글

마우스로 카메라 줌인 줌아웃 회전  (0) 2022.05.28
유니티  (0) 2022.05.21
유니티(Unity) VS 언리얼 엔진(Unreal Engine)  (0) 2022.05.21