help whit this camera script
this camera script allow me to show objects from specific cam my problem is i want to use more than one camera per object but this script allow just one cam per object unfortunately i dont have scripting experience to much can anyone help me to edit this script for support more than one cam per object?
public class LimitVisibility : MonoBehaviour
{
/** The _Camera to limit the GameObject's visibility to */
public _Camera limitToCamera;
/** If True, then child GameObjects will be affected in the same way */
public bool affectChildren = false;
/** If True, then the object will not be visible even if the correct _Camera is active */
[HideInInspector] public bool isLockedOff = false;
private _Camera activeCamera;
private bool isVisible = false;
private void Start ()
{
activeCamera = KickStarter.mainCamera.attachedCamera;
if (!isLockedOff)
{
if (activeCamera == limitToCamera)
{
SetVisibility (true);
}
else if (activeCamera != limitToCamera)
{
SetVisibility (false);
}
}
else
{
SetVisibility (false);
}
}
/**
* Updates the visibility based on the attached camera. This is public so that it can be called by StateHandler.
*/
public void _Update ()
{
activeCamera = KickStarter.mainCamera.attachedCamera;
if (!isLockedOff)
{
if (activeCamera == limitToCamera && !isVisible)
{
SetVisibility (true);
}
else if (activeCamera != limitToCamera && isVisible)
{
SetVisibility (false);
}
}
else if (isVisible)
{
SetVisibility (false);
}
}
private void SetVisibility (bool state)
{
if (GetComponent <Renderer>())
{
GetComponent <Renderer>().enabled = state;
}
else if (gameObject.GetComponent <SpriteRenderer>())
{
gameObject.GetComponent <SpriteRenderer>().enabled = state;
}
if (gameObject.GetComponent <GUITexture>())
{
gameObject.GetComponent <GUITexture>().enabled = state;
}
if (affectChildren)
{
Renderer[] _children = GetComponentsInChildren <Renderer>();
foreach (Renderer child in _children)
{
child.enabled = state;
}
SpriteRenderer[] spriteChildren = GetComponentsInChildren <SpriteRenderer>();
foreach (SpriteRenderer child in spriteChildren)
{
child.enabled = state;
}
GUITexture[] textureChildren = GetComponentsInChildren <GUITexture>();
foreach (GUITexture child in textureChildren)
{
child.enabled = state;
}
}
isVisible = state;
}
}
}
Answer by Jessespike · Jul 11, 2016 at 06:15 PM
You can set the layer on the objects and instruct the camera to only render that layer, culling the rest.
https://docs.unity3d.com/ScriptReference/Camera-cullingMask.html
tnx for your attention ''Jessespike'' because i use adventure creator asset and on 2.5d set cam culling mask is not work on it , i cant use Cam culling mask and layers so any help about this script or any other way ?
Your answer
Follow this Question
Related Questions
Find and turn off previous camera? 1 Answer
Where do you find camera target on tank game? 0 Answers
Center a Object at hit.point in Camera 2 Answers
Camera Collision Problem 0 Answers