1
我有一個攝像機預製,我在不同的位置實例化4次,我想在它上面添加渲染紋理(作爲目標紋理),所以我可以採用相同的紋理,並應用在一個場景中進行監視。請問是否不清楚。我試圖做一個監視監視,但不知道如何做到這一點,我堅持這一點。請舉例先謝謝。如何在實例化的相機上應用渲染紋理(作爲目標紋理)?
我有一個攝像機預製,我在不同的位置實例化4次,我想在它上面添加渲染紋理(作爲目標紋理),所以我可以採用相同的紋理,並應用在一個場景中進行監視。請問是否不清楚。我試圖做一個監視監視,但不知道如何做到這一點,我堅持這一點。請舉例先謝謝。如何在實例化的相機上應用渲染紋理(作爲目標紋理)?
我認爲統一手冊很好地解釋了它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-相機一點點每一秒,放入下渲染紋理從陣列和渲染圖像。最後,我禁用相機。這是當您將所有4個RenderTextures放在四邊形上時的結果:Result
感謝您的回覆。相機從預製中實例化。如何將渲染紋理渲染到實例化的相機並應用於視圖上。 – RingR89
您只需在資產窗口中將您的RenderTexture添加到相機預製件(使用上面的腳本)即可。當你實例化預製件時,它會引用你的RenderTextur資產。要顯示RenderTextures,只需添加一個Quad(或其他),然後拖動RenderTexture就可以更改其材質。一旦你的相機已經渲染你看到四邊形紋理。 –