Version: 2020.1
언어: 한국어
머티리얼 인스펙터 레퍼런스
스탠다드 셰이더를 사용하는 머티리얼에 대한 스크립팅

C# 스크립트로 머티리얼 사용

인스펙터 창에 표시되는 머티리얼 에셋의 모든 파라미터는 스크립트를 통해 액세스할 수 있으며 런타임 시 머티리얼의 작동 방식을 변경하거나 애니메이션화할 수 있는 권한을 부여합니다.

이렇게 하면 머티리얼의 숫자 값을 수정할 수 있으며 컬러를 바꾸고 게임플레이 동안 텍스처를 동적으로 스왑할 수 있습니다. 이를 수행하기 위해 사용되는 가장 일반적인 함수는 다음과 같습니다.

함수 이름 용도
SetColor 머티리얼의 컬러 변경(예: 알베도 틴트 컬러)
SetFloat 부동 소수점 값 설정(예: 노멀 맵 멀티플라이어)
SetInt 머티리얼의 정수 값 설정
SetTexture 머티리얼에 새 텍스처 할당

스크립트를 통해 머티리얼을 조정하는 데 사용할 수 있는 함수의 전체 세트는 머티리얼 클래스 스크립팅 레퍼런스에서 찾을 수 있습니다.

One important note is that these functions only set properties that are available for the current Unity shader on the material. This means that if you have a shader that doesn’t use any textures, or if you have no shader bound at all, calling SetTexture will have no effect. This is true even if you later set a shader that needs the texture. For this reason it is recommended to set the shader you want before setting any properties, however once you’ve done that you can switch from one shader to another that use the same textures or properties and values will be preserved.

이 함수는 레거시 셰이더와 스탠다드 셰이더 이외의 빌트인 셰이더(예: 파티클, 스프라이트, UI 및 조명이 꺼진 셰이더)와 같이 모든 간단한 셰이더가 예상하는 대로 작동합니다. 그러나 스탠다드 셰이더를 사용하는 머티리얼의 경우 머티리얼을 완전히 수정하기 전에 알아야 할 요구 사항이 있습니다.

머티리얼 인스펙터 레퍼런스
스탠다드 셰이더를 사용하는 머티리얼에 대한 스크립팅