빈 오브젝트를 만드는 코드는 아래와 같다.
생성자에 string을 넣어주면 string의 이름을 가진 빈 오브젝트가 생성된다.
GameObject empty = new GameObject("Empty");
그리고 유니티 3D Object에는 아래와 같이 6개의 프리미티브 타입의 오브젝트가 있다.
기본 오브젝트도 빈 오브젝트와 마찬가지로 스크립트로 만들 수 있다.
CreatePrimitive를 이용하면 6개 타입의 오브젝트를 만들 수 있다.
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
PrimitiveType에는 유니티가 만들어 둔 6개의 오브젝트가 있으므로, enum만 변경하면 쉽게 생성이 가능하다.
아래 코드를 빈 오브젝트에 추가한 후 실행해보자.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CreateObject : MonoBehaviour
{
void Start()
{
GameObject empty = new GameObject("Empty");
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
}
}
"Empty" 이름을 가진 빈 오브젝트와 Sphere가 생성되는 것을 알 수 있다.
Unity Plus:
Easy 2D, 3D, VR, & AR software for cross-platform development of games and mobile apps. - Unity Store
Have a 2D, 3D, VR, or AR project that needs cross-platform functionality? We can help. Take a look at the easy-to-use Unity Plus real-time dev platform!
store.unity.com
Unity Pro:
Unity Pro
The complete solutions for professionals to create and operate.
unity.com
Unity 프리미엄 학습:
Unity Learn
Advance your Unity skills with live sessions and over 750 hours of on-demand learning content designed for creators at every skill level.
unity.com
댓글