- Home /
Change prefab color when shuriken particle touches it
I would like to be helped please to change prefabs color if my shuriken particle touches it.
What I would like to do is that each particle that touches my prefab, it will make that prefab color darker and darker (so it will start as white, but change it's color to black after x amount of particles touched it).
Could anyone help me with a script for me that could do that?
Thank you.
Answer by violence · Nov 27, 2013 at 04:32 PM
Breaking your requirement up into parts, it seems this is what you need to do:
- Detect collision with your prefab 
- Detect the object it is colliding with 
- Change color of that object 
This is javascript, I dont know C# but I assume the conversion isn't difficult if required.
I think you can combine 1,2, and 3 into the OnTriggerEnter function: Unity Docs: OnTriggerEnter()
 /* This variable is the amount to which each RGB value is incremented down to 
 black each time it is collided with. RGB value of black is (0,0,0) so eventually 
 it will become black. The higher this number is the lower the number of collisions 
 to get to black.*/
     
 var change : float = 15.0
     
 // this function is called when a collision with this object is detected. 'other' is the object that is colliding with it.    
     
 function OnTriggerEnter (other : Collider) {
     
 other.gameObject.renderer.material.Color32.r = other.gameObject.renderer.material.Color32.r - change;
     
 other.gameObject.renderer.material.Color32.g = other.gameObject.renderer.material.Color32.g - change;
     
 other.gameObject.renderer.material.Color32.b = other.gameObject.renderer.material.Color32.b - change;
                 
 }
Disclaimer: I am not near a computer to test this out, Im sure there are some kinks. I can edit this later if you provide the issues that come up. Also, I am a noob, there very well may be a much easier way to do this.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                