- Home /
I want to change a cube's texture (or) Material by collision
I am really new to Unity and i know i ask a lot. But i would reallly appreciate if someone could help me with this.
I have a setup like this:
A plane with a lot of cubes on it. And a player that is walking on a path that is above that plane.
When the player hits a pickup I want a cube to fall down at that location. The cube then drops down on the other cubes.
I want the cubes that are hit by the cube that is falling to change color.
Is this possible and does someone know how ?
Answer by DaveA · Feb 27, 2011 at 10:16 PM
It's easy. If I had time I'd write it for you, but I don't right now. In the mean time, you can look at Collider:
http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html
and changing materials on a Renderer:
http://unity3d.com/support/documentation/ScriptReference/Renderer-material.html
I got it to change color now i just need to trigger that by collision, tried some stuff but failed kinda big time.
Thanks for you're help ^^ $$anonymous$$aybe you can guide me trough the collision trigger part ?
@cloudyheaven Just create a script and attach it to the collider you want the trigger. Then use this: void OnCollisionEnter(Collision collision) {YOURCODE};
Your answer