image.png
應(yīng)項(xiàng)目需求作為功能調(diào)研初期成果物薛夜,實(shí)現(xiàn)3D人物換裝靜態(tài)版袱蚓,二期會(huì)出動(dòng)態(tài)版敬請(qǐng)期待C锻搿S庖弧!
1.引入 fbx 格式的3D模型
存放在Assets下肮雨,F(xiàn)bx文件夾下存放的是模型
Pasted Graphic.png
2.將需要的模型(拖動(dòng))添加到工程
Pasted Graphic 1.png
3.在Assets下創(chuàng)建用于存放腳本的腳本文件夾
4.創(chuàng)建腳本(指定換裝腳本)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class changeindexmodel : MonoBehaviour
{
public GameObject[] Clothes;
// Start is called before the first frame update
void Start()
{
//Camera.main.GetComponent<Camera>().backgroundColor = new Vector4(0, 0, 0, 0);
GameObject.Find("Main Camera").GetComponent<Camera>().backgroundColor = Color.blue;
// changemodel("Kazuko");
}
// Update is called once per frame
void Update()
{
}
public void changemodel(string model)
{
for (int i = 0; i < Clothes.Length; I++)
{
if (Clothes[i].name == model)
{
Clothes[i].SetActive(true);
}
else
{
Clothes[i].SetActive(false);
}
}
}
}
5.創(chuàng)建按鈕遵堵,下圖空白處右鍵UI->Button,button按鈕可通過點(diǎn)擊Scenr下的2D 來查看
Pasted Graphic 2.png
6.首先選中左側(cè)Button 然后將changeindexmodel.cs拖至右側(cè)的Add Component處 ,將所有的用于替換的部位拖放置1處陌宿,將changemodel(string model)方法于2處的on click()做綁定锡足,至此可以運(yùn)行查看效果
Pasted Graphic 3.png
7.注意 changeindexmodel.cs不能捆綁多處,調(diào)整 camera的角度可通過點(diǎn)擊右上角的Front然后做微調(diào)