flrto

Unity에서 gameObject 와 GameObject의 차이 본문

Unity/TIL

Unity에서 gameObject 와 GameObject의 차이

갈릭새우칩 2019. 5. 17. 17:12

· gameObject는 컴포넌트 입장에서 자신이 추가된 게임 오브젝트를 가리키는 변수이다.

 

· gameObjectGameObject 타입변수 이고 컴포넌트들의 기반 클래스인 MonoBehaviour에서 제공한다.

 

코드 예제) 아래와 같이 gameObject.     <-으로 접근한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class PlayerController : MonoBehaviour
{
    void Start()
    {
        
    }
 
    void Update()
    {
 
    }
    public void Die()
    {
        //자신의 게임 오브젝트를 비활성화
        gameObject.SetActive(false);
    }
}
 
 

※ 모든 컴포넌트는 gameObject 변수를 이용해 자신을 사용 중인 게임 오브젝트(자신의 게임 오브젝트)에 접근할 수 있다.

 

gameObjectGameObject는 다르다!!  gameObject변수이고, GameObject타입이다.

 

 

Comments