- Home /
How do you programmatically retrieve the rendering camera from its render texture?
Programmatically if you have access to a render texture, how would you get access to the camera which rendered it?
Answer by JonManatee · Jun 16, 2010 at 09:39 PM
Render Textures do not include references to cameras, because that may not be the purpose for a given render texture. Instead a camera will include a reference to Camera.targetTexture, but not vice-versa. You would have to include your own support scripts for the render texture to inform your code which render texture is assigned to which camera.
Answer by naruse · Mar 22, 2010 at 11:36 AM
it is possible to know which camera is rendering your object (Bare in mind that more than one camera at the same time can be rendering your object).
Checkout this:
var anObject : GameObject; private var cam : Camera; private var planes : Plane[];
function Start() { cam = Camera.main; planes = GeometryUtility.CalculateFrustumPlanes(cam); }
function Update() { if(GeometryUtility.TestPlanesAABB(planes,anObject.collider.bounds)) Debug.Log(anObject.name + " has been detected!"); else Debug.Log("Nothing has been detected"); }
That code detects if an object is being "seen" by a camera. Hope it helps you out ;)
C# Version here as well:
using UnityEngine; using System.Collections;
public class example : MonoBehaviour { public GameObject anObject; private Camera cam; private Plane[] planes; void Start() { cam = Camera.main; planes = GeometryUtility.CalculateFrustumPlanes(cam); } void Update() { if (GeometryUtility.TestPlanesAABB(planes, anObject.collider.bounds)) Debug.Log(anObject.name + " has been detected!"); else Debug.Log("Nothing has been detected"); } }
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Using the accelerometer to rotate Camera 1 Answer
Need help with script, one time touch to the screen = synchronize camera with face 0 Answers
How to apply target, while created at runtime? 1 Answer
Mulit-Pass Custom Shader Workflow 1 Answer