I am geting these varnings in the unity 5 console: The class named 'LoadandSave' is not derived from MonoBehaviour or ScriptableObject!
GameObject (named 'GameSpawner') references runtime script in scene file.Fixing!
But I am not getting any errors or varnings in Visual Studio.
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public class GameData : MonoBehaviour
public Text ScoreText;
public Text Highscoretext;
public Transform player;
public static float Highscore = 0;
void Update()
{
ScoreText.text = player.transform.position.x.ToString("0");
if (player.transform.position.x > Highscore)
{
Highscoretext.text = player.transform.position.x.ToString("0");
}
}
}
public class LoadandSave
{
private void Awake()
{
Save();
}
public static void Save()
{
BinaryFormatter binaryformatter = new BinaryFormatter();
using (FileStream fs = new FileStream("gamesave.bin", FileMode.Create, FileAccess.Write))
{
binaryformatter.Serialize(fs, GameData.Highscore);
}
SceneManager.LoadScene(0);
}
public static void Load()
{
if (!File.Exists("gamesave.bin"))
{
return;
}
BinaryFormatter binaryformatter = new BinaryFormatter();
using (FileStream fs = new FileStream("gamesave.bin", FileMode.Open, FileAccess.Read))
{
GameData.Highscore = (int)binaryformatter.Deserialize(fs);
}
}
}
I have tried adding :MonoBehaviour att the end of public class LoadandSave.
But then the unity 5 editor wont start play. And just craches.