- Home /
Texturing/Coloring wherever you go
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!
Answer by gregzo · Dec 04, 2011 at 11:05 AM
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...
the problem is I have a big object and if i need to use this script i would have to divide that object into small-small parts..
the problem is I have a big object and if i need to use this script i would have to divide that object into small-small parts..
Then maybe use a spotlight that follows the player? Greyish, low intensity ambient light, wide spotlight following the player? If you give more details, I'm sure help can be more precise!
alright .. imagine the racing game where there are no colors and a colorful car races through the track making it colorful over the area it go .. not only specific places it go but whole back area where it is co$$anonymous$$g from ..
Your answer
Follow this Question
Related Questions
Finding color of a body at the point of collision with another body? 1 Answer
Detect if ball is on a platform or if it fell 4 Answers
Editing Texture during Run time causing Unity Editor to Crash 1 Answer
Adding sound javascript in unity2d 1 Answer
How to color text smoothly or how to color part of a letter? 1 Answer