- Home /
change instance color based on distance from player
Hi, I'm pretty new to Unity... I would like an instance to change color when my player is within a certain range... Is that possible? I tried changing the color of the material
float dist = Vector3.Distance(used1Other.position, transform.position); if(dist < 10){ usedMatUnit1.SetColor ("_Color", Color.red); }else{ usedMatUnit1.SetColor ("_Color", Color.white); }
and although that changes the color, it does that for all instances, and only on start of the game, while I would like it to be 'realtime' I want the instances to change color on the fly when the player gets near. I'm sure I'm doing something wrong or think about this the wrong way around but at this stage could need some help... Thanx!!! Hans
I'm still digging around in the overwhel$$anonymous$$g amount of answers and forum entries... I've found that I should use renderer.material.color ins$$anonymous$$d... not entirely sure how I should only address one of the used materials on the object though. Based on distance from my player it seems to work at starting the game, so the instances within the distance get the color, but on moving closer or further away with my player, nothing seems to happen... the instances keep their chosen color from startup.
$$anonymous$$gestions? Hans
Your answer
Follow this Question
Related Questions
material instance save 0 Answers
Alter Meshes in Editor by Script without warning 2 Answers
change GameObject color due to distance 1 Answer
Material doesn't have a color property '_Color' 4 Answers
Destroy instances after set time 1 Answer