- 最后登录
- 2013-7-18
- 注册时间
- 2011-7-16
- 阅读权限
- 70
- 积分
- 3247
 
- 纳金币
- 324742
- 精华
- 0
|
查看unity3d的换装demo,感觉比较繁琐,经自行试验,创建如下换装操作,具体步骤如下:
1、定义需要换装的GameObject,暂定为:Player
2、默认贴图贴好。
3、创建脚本 Cloth.js
1.var Cloth1 : Texture[];//上衣
2.
3. var Cloth2 : Texture[];//裤子
4.
5. var Properties_style : GUIStyle;//标签样式
6.
7. var int1 : int;
8.
9. var int2 : int;
10.
11. function Start()
12.
13. {
14.
15. int1 = 0;
16.
17. int2 = 0;
18.
19. }
20.
21. funciton OnGUI()
22.
23. {
24. GUI.Button(Rect(20, 10, 70,20),"Cloth",Properties_style);
25. GUI.Button(Rect(20, 35 + 25, 70,20),"Trousers",Properties_style);
26. if (GUI.Button(Rect(100, 10, 20, 20),">"))//换上衣
27.
28. {
29.
30. int1++;
31.
32. if (int1 > Cloth1.length - 1) int1 = 0;
33.
34. renderer.materials[0].mainTexture = Cloth1[int1];//此处materials[0]表示你衣服贴图材质球所处的位置,下面同此
35.
36. }
37.
38. if (GUI.Button(Rect(100, 35, 20, 20),">"))//换裤子
39.
40. {
41.
42. int2++;
43.
44. if (int2 > Cloth2.length - 1) int2 = 0;
45.
46. renderer.materials[1].mainTexture = Cloth2[int2];
47.
48. }
49.
50. }
4、把Cloth.js绑定到Player上,然后定义Cloth1和Cloth2这2个数组长度,放上相应的Texture,即可运行查看效果了。
|
|