본문 바로가기

게임프로그래밍

[MMO Lab 1기] GameObject vs Component

** 게임 오브젝트 > 컨포넌트, 스크립트(동작을 부여)

 

** 게임 오브젝트(GameObjects)는 Unity의 기초적인 오브젝트로 캐릭터, 소품, 배경을 나타냄  
   독자적으로 많은 것을 하기보다는 실질적 기능을 수행하는 컴포넌트(Components) 의 컨테이너 역할

** 컴포넌트는 해당 게임 오브젝트의 동작 정의

 

** 유니티 생명주기 중 Awake, Start, Update 숙지하기

   ㄴ Awake : 객체를 만들때

   ㄴ Start : 게임 시작

   ㄴ Update : 매 프레임마다

 

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    [SerializeField]
    int level = 1;

    [SerializeField]
    int hp = 100;

    [SerializeField]
    string id = "shine";


    void Awake()
    {
        
    }

    // Start is called before the first frame update
    void Start()
    {
        GameObject go = gameObject;

        SpriteRenderer sr = go.GetComponent<SpriteRenderer>();
        Transform tr = go.GetComponent<Transform>();

        Debug.Log(tr.position);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

 

 

** 공부할때, 참고한 블로그

https://wergia.tistory.com/162

 

[Unity3D] Tutorial (6) - 게임 오브젝트와 컴포넌트

Tutorial (6) 게임 오브젝트와 컴포넌트 작성 기준 버전 :: 2018.3.2f1 이번 섹션에서는 게임 오브젝트와 컴포넌트에 대해서 알아보자. 게임 오브젝트(Game Object) 게임 오브젝트는 유니티 엔진에서 가장

wergia.tistory.com

 

https://docs.unity3d.com/Manual/ExecutionOrder.html

 

Unity - Manual: Order of execution for event functions

Instantiating Prefabs at run time Order of execution for event functions Running a Unity script executes a number of event functions in a predetermined order. This page describes those event functions and explains how they fit into the execution sequence.

docs.unity3d.com

 

https://docs.unity3d.com/kr/2019.4/Manual/class-GameObject.html

 

게임 오브젝트 - Unity 매뉴얼

게임 오브젝트(GameObjects) 는 Unity의 기초적인 오브젝트로 캐릭터, 소품, 배경을 나타냅니다. 독자적으로 많은 것을 하기보다는 실질적 기능을 수행하는 컴포넌트(Components) 의 컨테이너 역할을 합

docs.unity3d.com

 

https://docs.unity3d.com/kr/2019.4/Manual/Components.html

 

컴포넌트 소개 - Unity 매뉴얼

게임 오브젝트는 컴포넌트를 포함하고 있는 Unity 에디터의 오브젝트입니다. 컴포넌트는 해당 게임 오브젝트의 동작을 정의합니다.

docs.unity3d.com