人物换装备
- 制作一个开始界面分别有三个可以更换角色服装的按钮。
- 点击"保存并进入游戏"按钮即可进入游戏场景,在游戏场景诞生角色,并且,角色身上的装备是在开始界面保存的装备效果.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ChageRoleCloth : MonoBehaviour
{
public Texture[] cloth;
private SkinnedMeshRenderer clothRenderer;
public GameObject weapon;
private int clothIndex = 0;
public Mesh[] wpModeCloth;
private MeshFilter wpMode;
public Texture[] wpCloth;
private Renderer wp;
private void Start()
{
clothRenderer = this.GetComponentInChildren<SkinnedMeshRenderer>();
wpMode = weapon.GetComponent<MeshFilter>();
wp = weapon.GetComponent<MeshRenderer>();
}
private void OnGUI()
{
if (GUILayout.Button("服装1"))
{
clothRenderer.material.mainTexture = cloth[0];
wpMode.mesh = wpModeCloth[0];
wp.material.mainTexture = wpCloth[0];
clothIndex = 0;
}
if (GUILayout.Button("服装2"))
{
clothRenderer.material.mainTexture = cloth[1];
wpMode.mesh = wpModeCloth[1];
wp.material.mainTexture = wpCloth[1];
clothIndex = 1;
}
if (GUILayout.Button("保存服装,并开始游戏"))
{
PlayerPrefs.SetInt("clothIndex",clothIndex);
SceneManager.LoadScene("Goblin");
}
}
}