查看: 2477|回复: 0
打印 上一主题 下一主题

Unity3D换装系统浅析

[复制链接]
   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2012-1-21 09:34:19 |只看该作者 |倒序浏览
查看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,即可运行查看效果了。

分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-7-13 17:26 , Processed in 0.065272 second(s), 28 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部