CameraFacingBillboard
原地址:http://www.cnblogs.com/88999660/
描述
这个脚本使得它被连接到配合本身相机的对象。这对于要经常面对镜头,并以同样的方式了,因为它是有用的广告牌。
用法
将这个脚本上要面对镜头一个游戏对象。然后,选择的对象,请使用检查器来选择要面对的对象的相机。
你可能想Vector3.back改变Vector3.front,这取决于你的对象的初始方向。
技术讨论
请注意,该脚本不只是在相机指向的对象。相反,它使得在相同的方向摄像机的前进轴(即,该方向上的摄像机观察中)的对象点。这似乎是直觉错了,但实际上它是正确的实时计算机图形的单点透视的世界。
C# - CameraFacingBillboard.cs
using UnityEngine;
using System.Collections; public class CameraFacingBillboard : MonoBehaviour
{
public Camera m_Camera; void Update()
{
transform.LookAt(transform.position + m_Camera.transform.rotation * Vector3.back,
m_Camera.transform.rotation * Vector3.up);
}
}
MODS
此模块将另外:
-寻找默认的摄像机在场景中
建立一个空的“容器”物体做为广告牌的父母,并会旋转此对象来代替。这允许用户在一个预定的旋转分配给该广告牌对象。
-需要初始化。(刚才设置“autoInit”为“true”)
外挂作者:juanelo
/ / cameraFacingBillboard.cs V02
/ /由尼尔·卡特(NCarter)
/ /由胡安·卡斯塔涅达修改(juanelo)
/ /
/ /在两者之间GRP对象加入到上进行旋转
/ /添加自动找到主摄像头
/ /添加取消初始化状态,其中的脚本将做什么
using UnityEngine;
using System.Collections; public class CameraFacingBillboard : MonoBehaviour
{ public Camera m_Camera;
public bool amActive =false;
public bool autoInit =false;
GameObject myContainer; void Awake(){
if (autoInit == true){
m_Camera = Camera.main;
amActive = true;
} myContainer = new GameObject();
myContainer.name = "GRP_"+transform.gameObject.name;
myContainer.transform.position = transform.position;
transform.parent = myContainer.transform;
} void Update(){
if(amActive==true){
myContainer.transform.LookAt(myContainer.transform.position + m_Camera.transform.rotation * Vector3.back, m_Camera.transform.rotation * Vector3.up);
}
}
}
此模块将:
-寻找场景中的默认的摄像头
-允许默认轴被指定
外挂作者:海登·斯科特男爵(坞)
/ / CameraFacing.cs
/ /原来由尼尔·卡特(NCarter)
/ /由海登·斯科特男爵(码头)的改进型- http://starfruitgames.com
/ /允许指定的方向轴
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;
} void Update ()
{
// 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);
}
}
CameraFacingBillboard的更多相关文章
- 全景视频外包团队:U3D全景漫游(二)
单击Ambient Light,如下 调整为 即可设置完成 14.设置第一人称浏览 删除场景中Main Camera 将Project区域的Standard Assets下的Prefabs下的Firs ...
- unity3d Billboard
CameraFacingBillboard CameraFacingBillboard From Unify Community Wiki Jump to: navigation, searc ...
随机推荐
- Zebra_Dialog 弹出层插件
. Default dialog box, no custom settings. Click here to open. $.Zebra_Dialog('<strong>Zebra_Di ...
- 2、面向对象以及winform的简单运用(面向对象的四大基本特性)
面向对象的四大基本特性 面向对象的核心概念就是封装.抽象.继承.多态这四大基本特性,在这里先解释一下它们的定义: 封装:是一种隐藏信息的特性.找到变化并且把它封装起来,你就可以在不影响其它部分的情况下 ...
- 第四十四课:jQuery UI和jQuery easy UI
jQuery UI是jQuery官方提供的功能效果和UI样式.作为官方出的东西,它一直没有被人们看重,一是它没有datagrid,tree等UI库必备的东西,二是它修改太过频繁,体积庞大.其实它所有以 ...
- Asp.Net MVC 中实现跨域访问
在ASP.Net webapi中可以使用 Microsoft.AspNet.WebApi.Cors 来实现: public static class WebApiConfig { public s ...
- 《疯狂Java:突破程序员基本功的16课》读书笔记-第二章 对象与内存控制
Java内存管理分为两个方面:内存分配和内存回收.这里的内存分配特指创建Java对象时JVM为该对象在堆内存中所分配的内存空间.内存回收指的是当该Java对象失去引用,变成垃圾时,JVM的垃圾回收机制 ...
- 【poj1012】 Joseph
http://poj.org/problem?id=1012 (题目链接) 半年前的考试题..任然清晰的记得那次差10分就AK... 题意 约瑟夫环,有前k个好人,后k个坏人,要求使得后k个坏人先死的 ...
- Eclipse启动Tomcat错误:Several ports (8005,8009) required by Tomcat v6.0 Server at localhost are already
解决办法: 1.netstat -aon|findstr 8005 可查看指定端口号使用情况 2.tasklist |findstr 10452 找出占用指定进程Id的程序 3.taskkill /p ...
- C# WPF 显示图片和视频显示 EmuguCv、AForge.Net测试(续)
介绍 本文是接着上文<C# WPF 显示图片和视频显示 EmuguCv.AForge.Net测试>写的,建议先看下上文,因为有些代码还需要了解. 增添 接着上文的代码,我们可以在事件处理方 ...
- DALSA Coreco - 图像处理软件(Sapera LT )
http://blog.csdn.net/linglongyouzhi/article/details/3505845 概述 Sapera LT 是一套用于图像采集.显示和控制的独立于硬件以外的 C ...
- AngularJS 的数据绑定
单向绑定(ng-bind) 和 双向绑定(ng-model) 的区别 ng-bind 单向数据绑定($scope -> view),用于数据显示,简写形式是 {{}}. 1 <span n ...