Unity C# : Modifying Material in Script

  Рет қаралды 19,573

about game making

about game making

Күн бұрын

Пікірлер: 52
@kermitkitchen
@kermitkitchen 3 жыл бұрын
This is easily the best video I've seen on this so far.
@aboutgamemaking
@aboutgamemaking 3 жыл бұрын
I am so happy that the tutorial really helped you. Thank you for watching! :)
@twosoulfox
@twosoulfox 2 жыл бұрын
Your topics and concepts are interesting. Also your older animations and ideas. I hope you can work in a good environment. Kind regards.
@aboutgamemaking
@aboutgamemaking 2 жыл бұрын
Thank you ! I will keep it up. :)
@ShatabdaRoy115
@ShatabdaRoy115 2 жыл бұрын
I am quite surprised how this tutorial is rich with info... Like no joke
@aboutgamemaking
@aboutgamemaking 2 жыл бұрын
I really thank you!! ,,ㅎㅅㅎ,,
@ShatabdaRoy115
@ShatabdaRoy115 2 жыл бұрын
@@aboutgamemaking whats ur discord mate?
@aboutgamemaking
@aboutgamemaking 2 жыл бұрын
@@ShatabdaRoy115 Sorry, I don't use Discord. :(
@ShatabdaRoy115
@ShatabdaRoy115 2 жыл бұрын
@@aboutgamemaking np I wish our path meet us again ;)
@aboutgamemaking
@aboutgamemaking 2 жыл бұрын
@@ShatabdaRoy115 Sure thing. I will get the Discord account when the company's work is done.
@MayKayy
@MayKayy 11 ай бұрын
You are the best!
@Cherry_Dev
@Cherry_Dev 2 жыл бұрын
Where i can download the script?
@eyestorm3289
@eyestorm3289 3 жыл бұрын
awesome video, thank you very much
@DatCameraMON
@DatCameraMON 2 жыл бұрын
What if you aren't using a Standard material and are using a URP material?
@aboutgamemaking
@aboutgamemaking 2 жыл бұрын
Do you mean modifying material properties in URP shader? It is same as the tutorial video. As you can see the tutorial, I accessed properties' names and changed their values. Therefore, there are no differences in between standard and urp shaders.
@DatCameraMON
@DatCameraMON 2 жыл бұрын
@@aboutgamemaking Nevermind, I figured it out. You have to use: (lead up stuff).material.SetTexture("_BaseMap", (textureName)); to switch it for URP materials, I believe. In my case, I also was messing up which Renderer was assigned. I forgot that my character had a Skinned Mesh Renderer attached to the body, which was under the Player object and what I needed to assign as the Renderer variable.
@deicide2324
@deicide2324 3 жыл бұрын
Hi, what if I wanna to disable or enable all the materials in the model by click a button?
@aboutgamemaking
@aboutgamemaking 3 жыл бұрын
Do you mean remove the texture?
@deicide2324
@deicide2324 3 жыл бұрын
@@aboutgamemaking I don't think so? I am a new for unity and the model's material is applied color from Blender.
@aboutgamemaking
@aboutgamemaking 3 жыл бұрын
@@deicide2324 Ok, What you have do is, you better know what do you want to express exactly in your game. Let say about the 'Example'. Hope you understand what I'm sayng. :) Could you explain about your example?
@deicide2324
@deicide2324 3 жыл бұрын
@@aboutgamemaking Actually this is my final year project, the model consists of more than 1000 "parts" and each part has more than 1 color. What I want to do is to change all of colors in the parts to "white".
@aboutgamemaking
@aboutgamemaking 3 жыл бұрын
@@deicide2324 Alright, There many ways to change color. 1st one is change shader's property, for instance "_MainColor" or "_Color". If you use Unity's standard shader or built in shader, you can access one of shader's properties called "_MainColor". The second one is also access Standard shader's Emission and change its color. The 3rd one is change the Texture, but it might causes lots of CPU or GPU usage. In Summery, I recommend access the object's materials and shader's properties. So, you might access objects' 'Renderer' and access Renderer's Material. Actually, I'm telling you about the tutorial's content. :)
@maitrykotak3703
@maitrykotak3703 Жыл бұрын
is there any helpful video for changing object like on button click new gun model come in unity..please refer
@aboutgamemaking
@aboutgamemaking Жыл бұрын
Check the tutorial down below : kzbin.info/www/bejne/fH-yaGiwbt2BZ6s
@smorazzi7494
@smorazzi7494 2 ай бұрын
How can i change emission intensity via script? I can't find it. Usefull video! I hope u can upload more videos as this! Thank you!
@aboutgamemaking
@aboutgamemaking 2 ай бұрын
Emission, or the intensity of luminescence, is controlled by the brightness of the color. However, it would be possible to control only the intensity while maintaining a specific Emission color at runtime, but it would be a very cumbersome process. A realistic way would seem to be to create a custom shader. I will consider creating a tutorial on this issue in the future.
@fariahuq6473
@fariahuq6473 3 жыл бұрын
Hi! Thanks for this great tutorial! One of the best for Shader manipulation via scripting. Can you kindly tell me what is the difference between renderer.material and renderer.sharedmaterial? I sometimes encountered that renderer.material does not work correctly but renderer.sharedmaterial does.
@aboutgamemaking
@aboutgamemaking 3 жыл бұрын
1. Changing properties with 'SharedMaterial' persists the changed properties even after gameplay stops. 2. On the other hand, if you stop the game after changing the properties of a shader or material with the 'Material' command, it will return to its original state. When rendering objects, the 'SharedMaterial' of the Renderer component is used by default, but a copy of the SharedMaterial is created when using the 'Material' command. You'll have to test it out to understand this. Try creating a runtime script for two objects that use the same material, changing one to blue and the other to red. If you have tested and verified the above, it will be easier to understand. ,,ㅎㅅㅎ,,
@fariahuq6473
@fariahuq6473 3 жыл бұрын
That makes so much sense! Thanks a lot again for the detailed answer. Would love to see more of your great resources on texture and material manipulating via script 😄
@AndrewNumptyPants
@AndrewNumptyPants 2 жыл бұрын
Awesome
@WerIstWieJesus
@WerIstWieJesus 2 жыл бұрын
More videos about Unity "in script" please!!!
@aboutgamemaking
@aboutgamemaking 2 жыл бұрын
I will try. ㅠㅅㅠ (crying)
@WerIstWieJesus
@WerIstWieJesus 2 жыл бұрын
@@aboutgamemaking I whish you the best.
@aboutgamemaking
@aboutgamemaking 2 жыл бұрын
@@WerIstWieJesus Thank you!
@kuhan9254
@kuhan9254 3 жыл бұрын
Nice video :)
@aboutgamemaking
@aboutgamemaking 3 жыл бұрын
Thank you ! :D
@Krazion669
@Krazion669 3 жыл бұрын
Thank you for the tutorial, it was very helpful. If an object has multiple materials, how would I select which material to change? For example, my object has pupils, cornea, and irises as materials. When I click the button to change materials, it changes the pupils (which is the first material). How could I change the script to change the irises material?
@aboutgamemaking
@aboutgamemaking 3 жыл бұрын
Before I help you, I have a question. If you have multiple materials applied to your character's eyes, are the pupil, cornea, and iris as separate GameObjects?
@Krazion669
@Krazion669 3 жыл бұрын
@@aboutgamemaking No, the materials are all part of the same game object.
@aboutgamemaking
@aboutgamemaking 3 жыл бұрын
@@Krazion669 OK, applying multiple material means the material component supports array variables. Therefore, you need Renderer variable with Array, like this : Renderer[] rend; After get Renderer compornent, you will be able to access each renderer with index number, like : rend[0].material.( certain elements from material) ; or you have to test it via debug : Debug.log (rend[0].material. [ ] ); Try it and give me the result. :)
@SceneOfAction
@SceneOfAction 2 жыл бұрын
What a great tutorial! I tried the method you replied with for multiple mats on one object but it didn't work so I tried this and it DID! The array is already built in if you have multiple materials on one object so this line worked without changing anything else. Just add an s to material (because it's plural if there is more than one material on the object), then set the number in the material array you want to change: _renderer.materials[2].SetTexture("_MainTex", newTex); Thanks for the great tutorial!
@mandrake1017
@mandrake1017 3 жыл бұрын
Muchas gracias!!
@aboutgamemaking
@aboutgamemaking 3 жыл бұрын
¡Eres bienvenido! ¡Muchas gracias por ver mi video!
@joeywang2024
@joeywang2024 4 жыл бұрын
Great!
@aboutgamemaking
@aboutgamemaking 4 жыл бұрын
Thank you! ( ,,ㅎㅅㅎ,,)
@hugodalben1738
@hugodalben1738 2 жыл бұрын
Thanks
@테이-q6z
@테이-q6z 4 жыл бұрын
GOOD!!
@aboutgamemaking
@aboutgamemaking 4 жыл бұрын
Thank you! ( ㅍㅅㅍ)
@StickyLabDev
@StickyLabDev Жыл бұрын
now iknow ,hope i can , _BaseMap cause i used render peplain yeah wakwak
Unity C# : Character Control - Rotate and move forward
10:56
about game making
Рет қаралды 38 М.
Scripting: Change Material of an Object | Unity Tutorial
5:31
Rosscoe Tutorials
Рет қаралды 139 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
I Made the Same Game in 8 Engines
12:34
Emeral
Рет қаралды 4,4 МЛН
Can AI Code Minecraft? Watch ChatGPT Try
8:06
BadGameDev
Рет қаралды 1,5 МЛН
Trying to Recreate the Coolest Star Wars VFX Scene
10:39
ErikDoesVFX
Рет қаралды 3,2 МЛН
Dear Unity Devs C++ is NOT that Hard
8:33
The Game Dev Cave
Рет қаралды 40 М.
5 ways to Reference GameObjects in Unity3D
11:49
Jason Weimann (GameDev)
Рет қаралды 133 М.
Events & Delegates in Unity
13:20
Game Dev Beginner
Рет қаралды 68 М.
10 Unity Tips You (Probably) Didn't Know About
6:47
Sasquatch B Studios
Рет қаралды 51 М.
How to Code (almost) Any Feature
9:48
DaFluffyPotato
Рет қаралды 718 М.