How to make an object glow without also changing other objects using same material?

I’m shooting lasers at asteroids. The lasers “heat up” the asteroids, which explode if they get too hot. I want to make this clear to players without making them read an explanation or go through a tutorial, so I tried having the diffuse color value on an asteroid’s shader increase its red component as the asteroid takes damage (and reduce as the asteroid cools down).

This looked great, except that every asteroid using the same material also got redder. I’m sure creating a new material for each asteroid is probably the wrong idea for performance, and even if it isn’t I feel like the code would be messy and complicated - is there a more elegant way to achieve this effect, where some asteroids glow redder while others do not?

1. get meshRenderer 2. Renderer.sharedmaterial this should work

i adjusted the script to check every second and change a bool for you. this certainly wont cause any preformance issues. just put this on your player and your done! ...That easy!

unity has a vector three distance function but it checks 3d distance. i gave you one for 2d. its just a bit faster to calculate distance with 2 vectors which is all you need and it will check in a ring shape instead of a dome/sphere shape...just incase you end up with high places in your level! .

1 Answer

1

The answer is to use MeshRenderer.material instead of MeshRenderer.sharedMaterial. However, using that means you have to do some cleanup on your own, and the API documentation is unclear. See this question for details.