【Unity】unity 人物动态头像

首先开一下效果图


其实原理很简单,就是单独的一个摄像机 对准人物


首先创建一个Render Texture



然后再要看的相机身上加上相应代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DisPlayCamera
{
    public Camera _WindowCamera;
    public RenderTexture _windowTexture;

    private static DisPlayCamera instance;
    public delegate void deleSetText(GameObject go);
    public deleSetText OnSetText;
    public static DisPlayCamera Instance
    {
        get { return instance = instance ?? new DisPlayCamera(); }
    }

    public void InitWindowCamera()
    {
        _windowTexture = Resources.Load<RenderTexture>("Window");
        _WindowCamera = new GameObject("WindowCamera").AddComponent<Camera>();
        _WindowCamera.clearFlags = CameraClearFlags.SolidColor;
        _WindowCamera.orthographic = true;
        _WindowCamera.orthographicSize = 0.2f;
        _WindowCamera.nearClipPlane = 0f;
        _WindowCamera.farClipPlane = 0.8f;
        _WindowCamera.targetTexture = _windowTexture;
    }
    //public void SetWindowCameraPos(GameObject target)
    //{
    //    if (OnSetText != null)
    //    {
    //        OnSetText(target);
    //    }
    //    switch (target.gameObject.tag)
    //    {
    //        case "BP":
    //            _WindowCamera.orthographicSize = 0.08f;
    //            _WindowCamera.gameObject.transform.SetParent(target.transform.GetChild(0));
    //            _WindowCamera.gameObject.transform.localPosition = new Vector3(0, 0.25f, 0f);
    //            _WindowCamera.gameObject.transform.localEulerAngles = new Vector3(90, 0f, 0f);
    //            //_WindowCamera.gameObject.transform.rotation =
    //            //    Quaternion.LookRotation(
    //            //        (target.transform.GetChild(0).transform.position - _WindowCamera.gameObject.transform.position));
    //            break;
    //        case "YWBP":
    //            _WindowCamera.orthographicSize = 0.2f;
    //            _WindowCamera.gameObject.transform.SetParent(target.transform.GetChild(0));
    //            _WindowCamera.gameObject.transform.localPosition = new Vector3(0, -0.5f, 0.8f);
    //            _WindowCamera.gameObject.transform.localEulerAngles = new Vector3(-90f, -90f, -90f);
    //            break;
    //    }
    //}
}

主要就是加在 Render Texture 然后让相机的targetTrxture = 你创建的Render Texture 

然后再创建一个RawImage添加如下代码


  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Unity_阿黄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值