- Home /
Turning on Visibility for Camera
Hello People
I have a FPC that have contained to the X-axis for a scrolling game
I need to turn on the mesh renders when the camera hits a certain x pos
and off when the camera moves on (or better yet when Camera is in between certain values )
Any ideas how I would do this?
Thank you !
~Be
Answer by Bentoon · Mar 08, 2014 at 05:38 AM
Hey Guys, because of how much text needs to be turned on and off, I went with a simple idea:
Making GameObjects that I can duplicate adnauseum each has a plane with collision detection that turns the text elements on and off
Like So:
var myText: Transform;
function OnTriggerEnter (other : Collider) {
Debug.Log("planeHit");
myText.renderer.enabled = true;
}
Thanks for your help SirCrazy Any ideas on streamlining are welcome
~be
Answer by SirCrazyNugget · Mar 07, 2014 at 03:52 AM
Apply a layer to the objects which are to be hidden.
On the camera turn off that layer in the culling mask.
if(Camera.main.transform.position.x > 0){
//hide the layer
Camera.main.cullingMask &= ~(1 << LayerMask.NameToLayer("TheNameOfTheLayerToToggle"));
}else{
//show the layer
Camera.main.cullingMask |= (1 << LayerMask.NameToLayer("TheNameOfTheLayerToToggle"));
}
Obviously set up a trigger and have it just change when necessary though, this is only a simple example
//and if you'd prefer to toggle the layer
Camera.main.cullingMask ^= (1 << LayerMask.NameToLayer("TheNameOfTheLayerToToggle"));
Also, store the LayerMask instead of using the NameToLayer function each time too.
Thanks SirCrazy.
$$anonymous$$y problem is that I have a scrolling game with a lot of layers that will be popping on and off as the camera moves endlessly to the right...
So I will be turning layers on and off all the time in the Camera script (update function?)
$$anonymous$$aybe its better to put GameObjects that hold the elements that need to be turned on and off and set an on enter/ on exit script as the Camera Passes through...
Is such a thing possible?
So the Logic I am trying to put on each Game object would be something like:
on Collision ? ( the only thing that will be colliding is the FCP&Camera) {
Camera.main.culling$$anonymous$$ask |= (1 << Layer$$anonymous$$ask.NameToLayer("TheNameOfTheLayerToToggle"));
}
onExit? {
Camera.main.culling$$anonymous$$ask &= ~(1 << Layer$$anonymous$$ask.NameToLayer("TheNameOfTheLayerToToggle"));
}
But I am having a tricky time writing the code... Thanks!!!
~be
Your answer