- Home /
How to a 3d character transparent?
I have a 3d character in my game. Its in fbx format. I just want to know, how can I make it transparent during collision or during some event. I don't know how to make those textures transparent.
Please Help. Thank You.
Answer by rutter · May 07, 2014 at 08:06 PM
You're really asking two questions:
First, how do you write a script that reacts to collisions? That's complicated, but lucky for you there are dozens of good tutorials out there. If you've never written a script, before, you'll want to look up an introductory video. Once you're familiar with the basics, you can check out the OnCollisionEnter article in the scripting reference, or find another video about handling collision.
Now, as far as turning your character invisible, all you'll need to do is disable its renderer. If there is only one renderer, you can use the renderer
property of your object. If there are several renderers, you can use GetComponentInChildren to find and disable all of them. Again, there are tutorials for this on the net.
You will probably also want to turn your renderers back on, so that your object becomes visible again. You could use Invoke() to call another function X seconds from now.
Dear @rutter u got me totally wrong here. Firstly, I know how to write a script for collision events and second, Try'n find a difference between transparent and invisible. They mean different. I'm talking about 50% alpha value of the renderer and you are talking about 0% alpha.
I would just create a transparent material and make a swap on the event
+1
Why so angry? Actually, transparent is invisible, you are looking for a translucent effect :P
The answer by rutter still applies, find all the renderers with GetComponentInChildren. If your shader supports transparency, then simply modify the alpha value of the renderer.material.color , or else swap the renderer material as suggested by Noah1.
I'm talking about 50% alpha value of the renderer , perhaps you should have specified this in the question....
Answer by MSpiteri · May 08, 2014 at 10:59 AM
Hello, have you tried to change the shader of the renderer when the player gets hit. ie. Place this inside your OnCollisionEnter (PS: I do not have Unity on this PC, so I might have a syntax error in the code, but it should be something like this):
renderer.material.shader = Shader.Find( "Transparent/Diffuse" );
Then change the alpha to achieve the fading effect that you want.