123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using UnityEngine;
- using System;
- using System.IO;
- public class WriteInFileOld : MonoBehaviour
- {
- public int index = 0;
- private string path;
- private void Start()
- {
- string currentPath = Directory.GetCurrentDirectory();
- string reference = @"\Assets\Data_position\";
- string directory = currentPath + @"\Assets\Data_position";
- // create directory if not existing
- if (!Directory.Exists(directory))
- {
- Directory.CreateDirectory(directory);
- }
- // create file for path
- using (File.Create(currentPath + reference + "Walk" + index + ".txt"))
- {
- path = currentPath + reference + "Walk" + index + ".txt";
- }
- }
- // Start is called before the first frame update
- private void Update()
- {
- // Save position of Human leaders in file
- string pos = this.gameObject.transform.position.ToString("f6");
- string rot = this.gameObject.transform.rotation.ToString("f6");
- if (File.Exists(path))
- {
- try
- {
- using (StreamWriter file = new StreamWriter(path, true))
- {
- file.WriteLine(pos + "," + rot);
- }
- }
- catch (Exception e)
- {
- throw new ApplicationException("Something went wrong by writing into a csv file : ", e);
- }
- }
- }
- }
|