I am working on a 3D Platform-ish game… Its basic scheme is Black and White-ish what i want is that where ever the player object goes from that area (not that specific place but the whole area ) should get colored/textured a little help will be appreciated. Thank You!
Hi! I’m not sure I understand your definition of place/area. Assuming you have 4 rooms on screen, each room an “area”, you could do the following:
1-add the following script to every object you want to be affected
var basicTexture : Texture;
var colouredTexture : Texture;
function Start()
{
renderer.material.mainTexture = basicTexture;
}
function SwapTexture()
{
if(renderer.material.mainTexture == basicTexture)
{
renderer.material.mainTexture = colouredTexture;
}
else
{
renderer.material.mainTexture = basicTexture;
}
}
2-make all objects of a room(“area”) children of a trigger (invisible flat cube, isTrigger enabled)
-Add the following script to your triggers
function OnTriggerEnter(coll: Collider)
{
if(coll.tag == "player") // tag or name or transform whatever works for you
{
BroadCastMessage("SwapTexture");
}
}
function OnTriggerExit(coll:Collider)
{
if(coll.tag == "player") // tag or name or transform whatever works for you
{
BroadCastMessage("SwapTexture");
}
}
It’s rough, but should work. You could refine it by having one or two intermediate textures to smooth it out.
P.S.: I’m new to Unity, but this question seemed like one I could answer quite safely. @More experience coders : if my reply is inadequate please enlighten me, as I’m sure there are more elegant ways of doing this…