Unity中使用RawImage和RenderTexture在UI界面上投影其他相机拍摄的内容
a.单纯的用小窗显示物体
个人认为所谓的 “ 物体A跟随物体B运动 ” 表现为:二者表现为运动(平移、旋转)方向,速度在任何时刻表现一致。
1.在Project界面创建RenderTexture
2.在Hierarchy界面创建RawImage
3.选中第二个摄像机,将New Render Texture挂载上
4.选中RawImage,将New Render Texture挂载上
最终效果如下图所示
b.当小窗显示时,可以控制小窗移动
场景中有两个摄像机,分别挂在不同的脚本
第一个脚本MoveScript.cs
using UnityEngine;
using System.Collections;
public class MoveScript : MonoBehaviour {
public enum RotationAxes {
MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
public float minimumX = -360F;
public float maximumX = 360F;
public float minimumY = -60F;
public float maximumY = 60F;
public static bool isEnableMove;
float moveSensitivity = 1.0f;
float rotationX = 0F;
float rotationY = 0F;
//Quaternion originalRotation;
//鼠标缩放
public float sensitivity = 60f;
public float minFov = 50f;
public float maxFov = 70f;
public float speedMove = 10f;
private float speed;
void Start()
{
// Make the rigid body not change rotation
if (GetComponent<Rigidbody>())
GetComponent<Rigidbody>().freezeRotation = true;
// originalRotation = transform.localRotation;
speed = speedMove;
isEnableMove = true;
}
void Update()
{
fnRotate();
if (isEnableMove)
fnMove();
// fnScroll();
}
void fnRotate()
{
CharacterController controller = gameObject.GetComponent<CharacterController>();
if (Input.GetMouseButton(1))//0对应左键 , 1对应右键 , 2对应中键
{
if (axes == RotationAxes.MouseXAndY)
{
float rotationX = transform