当前位置:首页 » 网页前端 » unityvr相机脚本
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

unityvr相机脚本

发布时间: 2022-12-12 17:46:25

① Unity摄像机的脚本怎么写

新建脚本 挂载到摄像机上,然后把代码丢进去就行了。

public class Scale : MonoBehaviour

{

//速度

public float ChangeSpeed = 0.5f;

private float maximum = 13;

private float minmum = 7;

void Update()

{

if (Input.GetAxis("Mouse ScrollWheel") != 0)

{

//限制size大小

Camera.main.orthographicSize =Mathf.Clamp(Camera.main.orthographicSize, minmum, maximum);

//滚轮改变

Camera.main.orthographicSize =

Camera.main.orthographicSize - Input.GetAxis

("Mouse ScrollWheel") * ChangeSpeed;

}

}

}



Unity是一款由Unity Technologies研发的跨平台2D/3D游戏引擎:

它以交互的图型化开发环境为首要方式,编译器运行在Windows 和Mac OS X下,可发布游戏至Windows、Wii、OSX、iOS或HTML5等众多平台。此外,Unity 还是被广泛用于建筑可视化、实时三维动画等类型互动内容的综合型创作工具。



② unity3d 相机怎么添加脚本

由于项目需求,需要在unity中播放高清视频,视频分辨率达到了3840x1200。采用的是c++
plugin解码视频,提供图片纹理给unity渲染的方式。而在unity中使用的是rendertexture来保存解码的视频图片。为了方面调试,需要保存某一些时刻的图片数据到本地,可以采用下面的函数实现:
[csharp]
view
plain

[contextmenu("save
png")]
private
void
savetexturetofile()
{
if
(outputtexture
!=
null)
{
rendertexture
prev
=
rendertexture.active;
rendertexture.active
=
target;
texture2d
png
=
new
texture2d(outputtexture.width,
outputtexture.height,
textureformat.argb32,
false);
png.readpixels(new
rect(0,
0,
outputtexture.width,
outputtexture.height),
0,
0);
byte[]
bytes
=
png.encodetopng();
string
path
=
string.format("mp/raw
{0}.png",
random.range(0,
65536).tostring("x"));
filestream
file
=
file.open(path,
filemode.create);
binarywriter
writer
=
new
binarywriter(file);
writer.write(bytes);
file.close();
texture2d.destroy(png);
png
=
null;
rendertexture.active
=
prev;
}
}