인스펙터 창에 표시되는 머티리얼 에셋의 모든 파라미터는 스크립트를 통해 액세스할 수 있으며 런타임 시 머티리얼의 작동 방식을 변경하거나 애니메이션화할 수 있는 권한을 부여합니다.
이렇게 하면 머티리얼의 숫자 값을 수정할 수 있으며 컬러를 바꾸고 게임플레이 동안 텍스처를 동적으로 스왑할 수 있습니다. 이를 수행하기 위해 사용되는 가장 일반적인 함수는 다음과 같습니다.
함수 이름 | 용도 |
---|---|
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 및 조명이 꺼진 셰이더)와 같이 모든 간단한 셰이더가 예상하는 대로 작동합니다. 그러나 스탠다드 셰이더를 사용하는 머티리얼의 경우 머티리얼을 완전히 수정하기 전에 알아야 할 요구 사항이 있습니다.
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.