① 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;
}
}