Camera.main

在Unity项目的C#代码中可以看到Camera.main.transform.position、Camera.main.transform.eulerAngles、Camera.main.transform.rotation等代码。

那么Camera.main是什么意思呢?

Camera类

A Camera is a device through which the player views the world.

Camera类包含以下静态变量:

allCameras Returns all enabled cameras in the scene.
allCamerasCount The number of cameras in the current scene.
current The camera we are currently rendering with, for low-level render control only (Read Only).
main The first enabled camera tagged "MainCamera" (Read Only).
onPostRender Event that is fired after any camera finishes rendering.
onPreCull Event that is fired before any camera starts culling.
onPreRender Event that is fired before any camera starts rendering.

Description of Camera.main

The first enabled camera tagged "MainCamera" (Read Only).

Returns null if there is no such camera in the scene.

时间: 2024-08-07 04:15:21

Camera.main的相关文章

unity Camera.main.X找不到

在unity中编辑camera的脚本时遇到了这个问题 想要去访问并修改Camera的相关属性以期达到操纵主相机的目的,但是main老是找不到 原因: 脚本名称/类名设置成Camera了! 解决方法: 1. 使用 UnityEngine.Camera.main 代替 Camera.main 使用 2. 修改摄像机的脚本名/类名(只要不是Camera即可) 原文地址:https://www.cnblogs.com/yocichen/p/12287033.html

Camera.main.WorldToScreenPoint注意事项

背景: AR卡项目中,需要在识别出的模型上加上升级时粒子效果,需要在生成模型的位置最上层出粒子效果. 然后粒子飞向进度条,实现升级. 关键方法及注意事项: Camera.WorldToScreenPoint Unity官方文档 该方法转换后得到的是屏幕坐标,不是Script中能直接用的坐标; 在1024×768的设备中,转换得到的坐标范围是从屏幕左下角的(0,0)到屏幕右上角的(1024,768); 如果需要在Unity脚本中使用,参考以下内容... 可以看到,这里是按照2046×1536来根据

NGUI Camera 作为 Main Camera摄像机背景

NGUI - UIRoot - Camera 1.新建Layer层 - backgroundImg 2.设置UIRoot层次为backgroundImg 3.Dept : 设置与Main Camera一样,或者小于Main Camera Main Camera 1. Clear Flags : Depth only 2. Culling Mash : 取消自定义(backgroundImg)层,显示为Mixed...

camera.ScreenPointToRay(),camera.ScreenToWorldPoint()与Raycast()

camera.ScreenPointToRay(Input.mousePosition),自camera.tranform.position起经过Input.mousePosition发射一条ray并返回ray camera.ScreenToWorldPoint(Input.mousePosition+new Vector3(0, 0, (xxx))),将屏幕坐标转换为世界坐标,但必须赋z值,z值应为摄像机到该点所在平面的投影 不要忘记distance参数,使用layermask可能与dista

Unity3D Camera透视相机到正交相机插值

事实上效果并不怎么好,因为延迟光照下的很多效果不支持正交,许多后期效果会炸掉,需要酌情使用 通过对投影矩阵进行插值来实现 如果透视相机的远截面和正交相机的远截面差太多,插值时会很奇怪,需要注意. 效果: 代码: using UnityEngine; using System.Collections; public class ProjectionLerp : MonoBehaviour { [Range(0, 0.9f)] public float lerp; public float near

Camera & Render

1.void Render(); Description Render the camera manually. This will render the camera. It will use the camera's clear flags, target texture and all other settings. The camera will send OnPreCull, OnPreRender & OnPostRender to any scripts attached, and

camera旋转+模型移动

刚接触Unity不久,正处于用什么学什么的状态,遇到这个问题着实研究了一阵子,得到了一个比较笨的方法. 想要完成的功能有两个,一是摄像机绕着整个场景中的所有模型旋转,旋转的中心点是世界坐标的原点:二是不管摄像机旋转到什么位置,模型都能跟随鼠标进行移动. 单独的让摄像机绕世界坐标原点旋转可以使用transform.RotateAround(Vector3.zero, Vector3.down, mouseMovex * Time.deltaTime).但是问题来了,如果只是进行水平方向或是垂直方向

Unity 脚本<1>

RaycastHit2D hit = Physics2D.Linecast(targetPosition, targetPosition + new Vector2(x, y)); 猜测是linecast函数一旦检测到第一个碰撞体之后就会停止检测. 所以把自身检测进去之后就不会检测墙了.估计Physics.Raycast函数也有此性质,这里要注意一下. 2. Unity 2D两种常用判断点击的方法 1.Raycast法 原理相同于3D中得Raycast法,具体使用略有区别. RaycastHit

Unity3D拖动任意对象GameObject移动到任意地方

今天不是很忙,研究了一下拖拽GameObject移动到任意位置,沿x轴和z轴移动,其他的也就不说了,上代码: using UnityEngine; using System.Collections; public class DragAndDrog : MonoBehaviour {     private GameObject target;     private bool isMouseDrag;     private Vector3 screenPosition;     privat