- Home /
Question by
misterk99 · Sep 28, 2016 at 09:08 AM ·
cameramasklayermaskculling masklayer mask
How to detect if a specific layer is active in the camera's culling mask
Hello everyone, I am building a sim ish like game. I have a house with mutliple floors and you can move the camera a floor up or down. I achieve this by having each floor on diffrent layers and enabling and disabling them.
Now I would like to know if for example the layer "GroundFloor" is active.
How could I achieve this?
Scripts below:
/// <summary>
/// Sets the building parts.
/// </summary>
public void SetBuildingParts(){
//Creats a new LayerMask for all the layers that need to be renderd
_layerRenderStr = new LayerMask();
//Adds the default layers
_layerRenderStr += defaultLayers;
//Adds the floor layers that need to be renderd
for(int i=0;i<buildingLayers.Length;i++){
if(visableBuildingLayer >= i){
_layerRenderStr.value += buildingLayers[i];
}
}
//Sets the layers that the camera needs to render
mainCamera.GetComponent<Camera>().cullingMask = _layerRenderStr;
//Sets the camera height to the height of the selected floor
cameraPoint.transform.position = new Vector3(cameraPoint.transform.position.x, floorAtHeight[visableBuildingLayer], cameraPoint.transform.position.z);
//Sets the floor text
floorText.text = ((LanguageTranslator.GetTranslationFromLanguage("Roof") != null)? LanguageTranslator.GetTranslationFromLanguage("Etage") : "LEVEL") + " " + visableBuildingLayer;
}
/// <summary>
/// Floors up.
/// </summary>
public void FloorUp(){
if(LayerMask.NameToLayer("GroundFloor").)
//If the floor can go up
if(visableBuildingLayer < buildingLayers.Length - 1){
visableBuildingLayer++;
SetBuildingParts();
}
}
/// <summary>
/// Floors down.
/// </summary>
public void FloorDown(){
//If the floor is not equal to the ground floor
if(visableBuildingLayer > 0){
visableBuildingLayer--;
SetBuildingParts();
}
}
Comment
Your answer
Follow this Question
Related Questions
Camera culling without layer mask 0 Answers
Mario Camera Culling Mask (Secret Areas), 1 Answer
Log Layers in Culling Mask 0 Answers
UI with layer always displaying 0 Answers
Render an layer from the position of player to a specific distance 0 Answers