Character from transparent to opaque

When the boy close to those ball, the boy will become translucent.

So these ball will not block by boy's body.

Player (we) will see boy eat those ball.

My idea is:

Create a big cube to cover with those ball.

And let big cube don't show on scene.

As long as people within big cube, the boy will become translucent.

But the boy is out of big cube, the boy will restore to original appearance (opaque).

What can I do this code?

Thanks everybody :)

alt text

I'm guessing (hoping) English is not your main language? =P

So what you're asking for is the boy to become transparent so he does not block the ball when he is within a certain area?

If that's the case, there's multiple parts to your code you will need to accomplish, I'll give you the basics to get you started, but if you don't know enough to do anything past that, just reply back and I'll see if I can walk you through the rest...

For one, you're going to want to access the alpha component of the boy's material, if you change that value it will make him simi-transparent. Material script referance: http://unity3d.com/support/documentation/ScriptReference/Material.html Color.alpha script referance: http://unity3d.com/support/documentation/ScriptReference/Color-a.html

So your code will have a line that looks something like:

renderer.material.color.a = (whatever value you choose here);

And of course you'll want some way to trigger that line, and from what I can make out, you want to do that with a triggerbox. So you'll take a cube (turn off its renderer so that it is see-through) and check the "Is trigger" part of this box. Then you're going to use a OnTriggerEnter function http://unity3d.com/support/documentation/ScriptReference/Collider.OnTriggerEnter.html

except you'll want it to check for when specifically the player enters. You can do this by adding a line to check the tag of whatever enters the triggerbox, then make sure you give the boy a "Player" tag

if (other.gameObject.tag == "Player") {  //do stuff here}

Thank you very much!!! I succeed!!!!

But I have a warning:

ArgumentException: Find can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. collision_cube..ctor () (at Assets/Standard Assets/Scripts/collision_cube.js:1)

How can I solve this problem?


Im Taiwanese and my English isnt good haha.

First, I choose "shadow material" to big cube's materials.

Let it becomes transparent.

In this way, cube doesnt show.

Tag name is called glass.

Second, put this script into boy:

(Boy's model is compose by 5 polygon)

var shader1 : Shader = Shader.Find( "Diffuse" );
var shader2 : Shader = Shader.Find( "FX/Glass/Stained BumpDistort" );
var face : GameObject;
var face2 : GameObject;
var face3 : GameObject;
var face4 : GameObject;
var face5 : GameObject;

function OnTriggerStay(other : Collider){
if (other.gameObject.tag == "glass" )  {
face.renderer.material.shader = shader2;
face2.renderer.material.shader = shader2;
face3.renderer.material.shader = shader2;
face4.renderer.material.shader = shader2;
face5.renderer.material.shader = shader2;
}
}

function OnTriggerExit(other : Collider){
if (other.gameObject.tag == "glass" )  {
face.renderer.material.shader = shader1;
face2.renderer.material.shader = shader1;
face3.renderer.material.shader = shader1;
face4.renderer.material.shader = shader1;
face5.renderer.material.shader = shader1;
}
}

Thank you very much again :)