- Home /
How to swap texture on object upon collision?
Hi people, I'm pretty new to unity and bad at scripting. Recently I just started making a simple racing game using this car tutorial: http://u3d.as/content/unity-technologies/car-tutorial/1qU
Ok, now the question is I want to implement some sort of car damage when it hits something(side of the track etc). Since I'm real bad at this, i decided the easiest way would be to simply swap out the material on the car for another one when it collides to fake the effect of having scratches on the car. But I really don't know how to go about doing it, help would be greatly appreciated! TIA :D
Which object should i used for the collision?
Answer by fafase · Jun 25, 2013 at 05:57 PM
You need to define a "health" for the car and define at what point you want to swap the material
public Material healthy;
public Material notSoHealthy;
int changingMat= aValue;
int health;
void GetHit(int damage){
health -= damage;
if(health < changingMat)renderer.material = notSoHealthy;
}
The method is called on collision.
Thanks! Will try this as soon as I get my PC fixed :/
Your answer
![](https://koobas.hobune.stream/wayback/20220613104851im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Change texure on NGUI BUTTUN press 0 Answers
How do I get a material to tile dynamically? 1 Answer
Path of the selected material's texture 0 Answers
Blending a Color with a Material Texture 1 Answer
Assigning UV Map to model at runtime 0 Answers