• Unity 如何使对象(文本(Text)模型精灵等)正面始终面向屏幕


    using UnityEngine;
    using System.Collections;
     
    public class CameraFacingBillboard : MonoBehaviour
    {
        public Camera m_Camera;
     
        //Orient the camera after all movement is completed this frame to avoid jittering
        void LateUpdate()
        {
            transform.LookAt(transform.position + m_Camera.transform.rotation * Vector3.forward,
                m_Camera.transform.rotation * Vector3.up);
        }
    }

    请注意,脚本不仅将对象指向相机。取而代之的是,它使对象指向与照相机前向轴相同的方向(即照相机向内看的方向)。从直觉上看,这可能是错误的,但实际上对于实时计算机图形的单点观点是正确的。

    //    CameraFacing.cs 
    //    original by Neil Carter (NCarter)
    //    modified by Hayden Scott-Baron (Dock) - http://starfruitgames.com
    //  allows specified orientation axis
     
     
    using UnityEngine;
    using System.Collections;
     
    public class CameraFacing : MonoBehaviour
    {
        Camera referenceCamera;
     
        public enum Axis {up, down, left, right, forward, back};
        public bool reverseFace = false; 
        public Axis axis = Axis.up; 
     
        // return a direction based upon chosen axis
        public Vector3 GetAxis (Axis refAxis)
        {
            switch (refAxis)
            {
                case Axis.down:
                    return Vector3.down; 
                case Axis.forward:
                    return Vector3.forward; 
                case Axis.back:
                    return Vector3.back; 
                case Axis.left:
                    return Vector3.left; 
                case Axis.right:
                    return Vector3.right; 
            }
     
            // default is Vector3.up
            return Vector3.up;         
        }
     
        void  Awake ()
        {
            // if no camera referenced, grab the main camera
            if (!referenceCamera)
                referenceCamera = Camera.main; 
        }
            //Orient the camera after all movement is completed this frame to avoid jittering
        void LateUpdate ()
        {
            // rotates the object relative to the camera
            Vector3 targetPos = transform.position + referenceCamera.transform.rotation * (reverseFace ? Vector3.forward : Vector3.back) ;
            Vector3 targetOrientation = referenceCamera.transform.rotation * GetAxis(axis);
            transform.LookAt (targetPos, targetOrientation);
        }
    }
  • 相关阅读:
    BZOJ1588_营业额统计_KEY
    关于欧几里得算法的认识
    javacv实战篇
    图像处理里面的的尺度什么?
    改成 否“依然报LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏”问题的解决
    javacv
    以前写过的一些oracle语句
    warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
    在vs环境中跑动sift特征提取(原理部分)
    《sift算法详解》阅读笔记
  • 原文地址:https://www.cnblogs.com/sy-liu/p/13955062.html
Copyright © 2020-2023  润新知