纳金网

标题: [二次开发]Unity3D换装系统创建 [打印本页]

作者: 驰骋的风    时间: 2012-10-12 11:31
标题: [二次开发]Unity3D换装系统创建
作者:xggxnn

  查看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绑[来源:GameRes.com]定到Player上,然后定义Cloth1和Cloth2这2个数组长度,放上相应的Texture,即可运行查看效果了。



来源:游资网 更多分享尽在Web3D纳金网http://www.narkii.com/
作者: mandonggua    时间: 2017-6-8 11:21
谢谢分享。




欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5