您的位置:首页 > 移动开发 > Unity3D

Unity3D-----持久化数据案例应用

2020-06-04 04:48 393 查看

人物换装备

  • 制作一个开始界面分别有三个可以更换角色服装的按钮。
  • 点击"保存并进入游戏"按钮即可进入游戏场景,在游戏场景诞生角色,并且,角色身上的装备是在开始界面保存的装备效果.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
///<summary>
///
///</summary>
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");
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: