Hello! Please help! I have successfully made a level with a Terrain, a Rigidbody FPS Controller from Standard Assets → Characters and some other GameObjects. I needed a saving system - so I have started to google file implementations in JavaScript. I have found some examples - but it returns compiler errors!
OS is Windows 10 64-bit. Unity version is 5.5.1f1 64-bit. Code editor is Visual Studio 2015, line endings corrected to Windows line endings. Language is JavaScript (UnityScript). Code I have used:
#pragma strict
import System;
import System.IO;
var Filename : String = "save.ini";
private var rwfile;
var x;
var y;
var z;
var Player : GameObject;
private var startTime : int;
private var timer1 : int;
function TimerSet() {startTime = Time.time;}
function TimerUpdate() {
timer1 = Time.time;
if(timer1 > 60) {
Debug.Log("Saving");
Write();
TimerSet();}}
function WriterSetup() {
Debug.Log("File Writer setup...");
if (!File.Exists(Filename)) {
rwfile = File.CreateText(Filename);}
rwfile = OpenText(Filename);
Debug.Log("File Writer configured sucsessfully");}
function Write() {
rwfile.open("w");
x = Player.transform.position.x;
y = Player.transform.position.y;
z = Player.transform.position.z;
rwfile.WriteLine(x);
rwfile.WriteLine(y);
rwfile.WriteLine(z);
rwfile.close();}
function Start() {Debug.Log("Saver Script Setup");
WriterSetup();
TimerSet();}
function Update () {TimerUpdate();}