Horje
player ToJson unity Code Example
player ToJson unity
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<PlayerScript>();

    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<PlayerData>(json);
}



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




Csharp

Related
c vs c++ vs c# Code Example c vs c++ vs c# Code Example
params keycord as var name c# Code Example params keycord as var name c# Code Example
Unity OVR Headset Code Example Unity OVR Headset Code Example
move files from one folder to another using c# Code Example move files from one folder to another using c# Code Example
samsung sam Code Example samsung sam Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9