본질적으로 스크립트의 작성은 다른 컴포넌트와 마찬가지로 게임 오브젝트에 연결할 수 있는 자신만의 새로운 컴포넌트 타입을 만드는 것입니다.
인스펙터에서 편집 가능한 프로퍼티를 갖는 다른 컴포넌트와 마찬가지로 스크립트의 값을 인스펙터에서 편집할 수 있습니다.
using UnityEngine;
using System.Collections;
public class MainPlayer : MonoBehaviour
{
public string myName;
// Use this for initialization
void Start ()
{
Debug.Log("I am alive and my name is " + myName);
}
}
이 코드는 “My Name”이라고 표시된 인스펙터에 편집 가능한 필드를 생성합니다.
이름이 다음 규칙 집합 중 하나를 따르는 경우 인스펙터는 스크립트에서 변수 이름을 정의하는 것과 다른 방법으로 변수 이름을 표시할 수 있습니다.
“iPad” 또는 “x64”와 같이 이러한 규칙이 적용되지 않는 몇 가지 특별한 사례도 있습니다.
Unity는 변수 이름에 대문자가 있을 때마다 공백을 더해 인스펙터 레이블을 만듭니다. 하지만 이는 표시 목적일 뿐 코드에서는 항상 변수 이름을 사용해야 합니다. 이름을 편집한 후 재생을 누르면 입력한 텍스트가 포함된 메시지가 표시될 것입니다.
C#에서 인스펙터에서 변수를 확인하는 가장 간단한 방법은 변수를 public으로 선언하는 것입니다. 또는 SerializeField를 사용할 수도 있습니다. 반대로 HideInInspector를 사용하여 public 변수가 인스펙터에 표시되는 것을 방지할 수 있습니다.
사실 Unity에서는 게임 실행 중에 스크립트 변수 값을 변경할 수 있습니다. 정지시키고 다시 시작할 필요 없이 변경 사항의 효과를 직접 볼 수 있어 매우 유용합니다. 게임플레이가 끝나면 변수 값은 재생 이전으로 초기화됩니다. 따라서 영구적인 손실을 우려할 필요 없이 오브젝트의 설정을 자유롭게 미세 조정할 수 있습니다.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.