📜  player ToJson unity - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:42.892000             🧑  作者: Mango

代码示例1
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GlobalControl : MonoBehaviour
{
public GameObject Player;

public void Save()
{
    var player = Player.GetComponent();

    PlayerData playerdata = new PlayerData();
    playerdata.pos = player.transform.position;
    playerdata.curreceny = player.currency;
    playerdata.playerDebug = player.IsUsingDebug;

    string json = JsonUtility.ToJson(playerdata);
    Debug.Log("Player data has been saved");

    File.WriteAllText(Application.dataPath + "playerData.json", json);
    PlayerData loadedPlayerData = JsonUtility.FromJson(json);
}



public class PlayerData
{
    public bool playerDebug;
    public Vector3 pos;
    public int curreceny;
}
}