【发布时间】:2017-04-20 22:54:11
【问题描述】:
我有一个相机预制件,我在不同的位置实例化了 4 次,我想在其中添加渲染纹理(作为目标纹理),这样我就可以采用相同的纹理并应用到平面上以在其中一个场景中进行监控。请询问是否不清楚。我正在尝试进行监视监视,但不知道如何执行此操作,因此我陷入了困境。请举例提前谢谢。
【问题讨论】:
标签: c# android unity3d unity5 instantiation
我有一个相机预制件,我在不同的位置实例化了 4 次,我想在其中添加渲染纹理(作为目标纹理),这样我就可以采用相同的纹理并应用到平面上以在其中一个场景中进行监控。请询问是否不清楚。我正在尝试进行监视监视,但不知道如何执行此操作,因此我陷入了困境。请举例提前谢谢。
【问题讨论】:
标签: c# android unity3d unity5 instantiation
我认为统一手册解释得很好https://docs.unity3d.com/Manual/class-RenderTexture.html。
更具体一点,这里有一个可能的实现:
在 AssetFolder 中创建一些 RenderTextures,而不是您必须将它们链接到您的相机脚本才能渲染它们。将此文件添加到您的 TextureRender-Camera。
using System.Collections;
using UnityEngine;
public class Camera2Texture : MonoBehaviour {
public RenderTexture[] renderTextures;
private Camera cam;
private void Awake()
{
cam = GetComponent<Camera>();
}
private void Start()
{
StartCoroutine(RenderTexturesCoroutine());
}
IEnumerator RenderTexturesCoroutine()
{
for (int i = 0; i < renderTextures.Length; i++)
{
// just move the camera a little bit and focus the center of the scene
this.transform.position += Vector3.left * 2 * i;
cam.transform.LookAt(Vector3.zero);
cam.targetTexture = renderTextures[i];
yield return new WaitForSeconds(1f);
cam.Render();
}
cam.targetTexture = null;
this.gameObject.SetActive(false);
}
}
我启动一个协程,它每秒移动我的 TextureRender-Camera 一点,从数组中放入下一个 RenderTexture 并渲染图像。最后我禁用了相机。这是将所有 4 个 RenderTexture 放在 Quads 上的结果:Result
【讨论】: