- Home /
Saving/ Loading Script Weird Bug
I don't know if it's because I have a mac or if I messed up somewhere, but this script isn't working for some reason. I get an error that says Unexpected Symbol on the 20th line of code (20, 24).
Here's my code:
using UnityEngine;
using System.Collections;
using System;
using System.Text;
using System.IO;
public class SaveGame : MonoBehaviour {
String path;
String fileName;
// Use this for initialization
void Start () {
fileName = "/gameSave.txt";
}
// Update is called once per frame
void Update () {
path = Application.dataPath + fileName;
using (FileStream fs = File.Create(path)){
AddText(fs, "Your Game is Saved");
}
private static void AddText(FileStream fs, string value){
byte[] info = new UTF8Encoding(true).GetBytes(value);
fs.Write(info, 0, info.Length);
}
}
Answer by rutter · May 31, 2012 at 11:35 PM
Two things I notice:
There seems to be a hidden control character in your text, immediately following the opening paren in
using (FileStream
You have unbalanced parens. Looks like you need another closing paren at the end of your
Update()
function.
Your answer
![](https://koobas.hobune.stream/wayback/20220613072220im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Save & Loading Variables 2 Answers
Retrieving basic Strings and Ints from XML Files (JS) 0 Answers
I am getting a serialization exception error when trying to save and load in Unity? 2 Answers
Serializing / deserializing large lists 0 Answers
How to clear all the players that have played my games playerprefs? 2 Answers