unity3d使用脚本
① unity3d 怎么用脚本控制播放制定音乐文件
比较常用的方法,就是新建一个gameobject,然后添加audio source组件,在audio source组件中设置好自己要播放的音乐(音效),以及相关数据。当然,默认是对象一被实例化就播放,但是这个也可以在设置中取消。
新建一个脚本绑定到上面,然后可以通过audio.Play()来播放。
http://docs.unity3d.com/ScriptReference/AudioSource.html
② Unity3D 用脚本控制Shader参数
Unity3D用脚本控制Shader参数是:this.renderer.material.SetFloat("_Progress", 0.5f);
③ Unity3D中用JavaScript写脚本,如何引用其他JS脚本,调用其他脚本内的方法,
1、方法定义为static,直接类名.方法名调用;
如
class Main1{
public static function Add(j:int,i:int):void
{
Debug.Log(i+j);
}
}
Main1.Add(1,2);
2、new 一个对象,对象调用,如
var m:Main1 = new Main1();
m.Add(2,3);
3、GameObject.Find(),得到那个有这个脚本组件的GameObject,这个GameObject再GetComponent,得到script,scirpt再调用方法。
④ Unity3D中三种调用其他脚本函数的方法
第一种:被调用脚本函数为static类型,调用时直接用 脚本名.函数名()。很不实用……
第二种:GameObject.Find("脚本所在物体名").SendMessage("函数名"); 此种方法可以调用public和private类型函数
第三种:GameObject.Find("脚本所在物体名").GetComponent<脚本名>().函数名();此种方法只可以调用public类型函数
⑤ 在unity3D: c# 怎样调用另外一个c#脚本里面东西
例:第一个脚本名字为Class_1,第二个脚本名字为Class_2,Class_1调用Class_2
如果Class_2没有绑定在任何GameObject上,那在Class_1里写法:
Class_2 c2 = new Class_2();
如果Class_2绑定在GameObject上,那在 Class_1里写法:
Class_2 c2 = null;
void Start()
{
c2 = GameObject.Find("绑定的GameObject名字").GetComponent<Class_2>();
}
⑥ 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;
}
}
⑦ unity3d中如何用脚本控制自动显示百分数
1、首先在unity面板中设置好基本的组件Slider与Text。
2、其次设置空物体,挂脚本。
3、然后拖设置好的组件Slider与Text。Unity3D是由Unity Technologies开发的一个让玩家轻松创建诸如三维视频游戏、建筑可视化、闭辩实时三维动画等类型互动和态配内容的多平台的唤指综合型游戏开发工具,是一个全面整合的专业游戏引擎。