Error text: Type ‘UnityEngine.GameObject’ in Assembly ‘UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ is not marked as serializable.
System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers (System.RuntimeType type) (at <599589bf4ce248909b8a14cbe4a2034e>:0)
1 Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public class Save : MonoBehaviour
{
public static void SaveData()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/saveGame.gd");
bf.Serialize(file, GlobalNames.playerGO);
file.Close();
}
}
2 script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class GlobalNames : MonoBehaviour
{
public static GameObject playerGO;
void Awake()
{
playerGO = GameObject.FindWithTag("Player");
}
}
3 script:
void Update()
{
if(Input.GetKey(KeyCode.I))
{
Save.SaveData();
Debug.Log("Сохранение");
}
}
I press “I” and get an error. Help
