Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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;
}
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: vb.net single quote in string 
Csharp :: percentage random c# 
Csharp :: cannot access file being used by another process create file 
Csharp :: create viewport revit api 
Csharp :: wetter warendorf 
Csharp :: attribute c# get method name reflection 
Csharp :: using autofac with automapper .net 6 with dependency injection 
Csharp :: ef null check 
Csharp :: .net framework cheat sheet 
Csharp :: dotnet.com 
Csharp :: set main camera unity 
Csharp :: using c# 
Csharp :: change text color wpf 
Csharp :: rate game in unity 
Csharp :: how to delete file in c# 
Csharp :: how to clear a dictionary in c# 
Csharp :: how to check if a number is prime or not c# 
Csharp :: Nullable Types unity 
Csharp :: c# MD5.Create returning nul 
Csharp :: c# pass mouse events to parent 
Html :: input tag no suggestions 
Html :: how to open link in a new tab 
Html :: favicon html link 
Html :: meta no cache 
Html :: meta colors html 
Html :: a href mail 
Html :: html text justify 
Html :: regex to remove html tags python 
Html :: html make file input only images 
Html :: fullpage cdn 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =