Unity2D save/Load sistemi
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class scriptin ismi : MonoBehaviour
{
public float x;
public float y;
void Start()
{
if (File.Exists(@"C:\Users\90505\Desktop\4ağustos\save.txt"))
{
FileStream fs = File.OpenRead(@"C: \save.txt");
StreamReader sr = new StreamReader(fs);
float konumumX = float.Parse(sr.ReadLine());
float konumumY = float.Parse(sr.ReadToEnd());
transform.position = new Vector2(konumumX, konumumY);
Debug.Log(konumumY);
Debug.Log(konumumX);
sr.Close();
fs.Close();
}
else
{
FileStream fs = File.Create(@"C:\Users\90505\Desktop\4ağustos\save.txt");
fs.Close();
}
}
private void Update()
{
}
// Update is called once per frame
private void OnTriggerStay2D(Collider2D collision)
{
if(collision.gameObject.tag == "save")
{
if (File.Exists(@"save dosyasının yolu"))
{
FileStream fs = File.OpenWrite(@"C: \savedosyasının ismi.txt");
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(transform.position.x);
sw.Write(transform.position.y);
sw.Close();
fs.Close();
}
else
{
FileStream fs = File.Create(@"save dosyasının yolu");
fs.Close();
}
}
}
}