- 最后登录
- 2016-8-29
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 23585
- 纳金币
- 20645
- 精华
- 62
|
查看unity3d的换装demo,感觉比较繁琐,经自行试验,创建如下换装操作,具体步骤如下:
1、定义需要换装的GameObject,暂定为:Player
2、默认贴图贴好。
3、创建脚本 Cloth.js- var Cloth1 : Texture[];//上衣
- var Cloth2 : Texture[];//裤子
-
- var Properties_style : GUIStyle;//标签样式
- var int1 : int;
- var int2 : int;
- function Start()
- {
- int1 = 0;
- int2 = 0;
- }
- funciton OnGUI()
- {
- GUI.Button(Rect(20, 10, 70,20),"Cloth",Properties_style);
- GUI.Button(Rect(20, 35 + 25, 70,20),"Trousers",Properties_style);
- if (GUI.Button(Rect(100, 10, 20, 20),">"))//换上衣
- {
- int1++;
- if (int1 > Cloth1.length - 1) int1 = 0;
- renderer.materials[0].mainTexture = Cloth1[int1];//此处materials[0]表示你衣服贴图材质球所处的位置,下面同此
- }
- if (GUI.Button(Rect(100, 35, 20, 20),">"))//换裤子
- {
- int2++;
- if (int2 > Cloth2.length - 1) int2 = 0;
- renderer.materials[1].mainTexture = Cloth2[int2];
- }
- }
复制代码 4、把Cloth.js绑定到Player上,然后定义Cloth1和Cloth2这2个数组长度,放上相应的Texture,即可运行查看效果了。
|
|