Quantcast
Channel: Visio General Questions and Answers for IT Professionals forum
Viewing all articles
Browse latest Browse all 2333

help whit this C# unity code

$
0
0

this code give me one camera per object i want more than one camera per object any help will be grateful


	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;
		}

	}

}


Viewing all articles
Browse latest Browse all 2333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>