How to write game data into external files in `Unity 3D` using `C#`
Blog Logo
on
read
You can write data in a stream form. Can also use formatted string similar with C or C++.
Open several files for writing like this below. If the file exists, it will be overwritten.
Write data like this:
You can let some game object in the scene to handle all file staff. I put _recordFile into a script named GameDataRecorder. And hang it to a game object in the scene named GameDataRecorder. Finally, open some interfaces to let other script to use the file stream like this:
In other script that wants to use the file to write can code like this:
And write data like this:
At last, don’t forget to close the file before application quit.
Written by
Blog Logo
Honglei Han 韩红雷
Published
Supported by
Image
Honglei Han 韩红雷的主页
Honglei Han from CUC
中国传媒大学 游戏设计 韩红雷
科研信息 所带课程 个人介绍 开源项目 创作的部分古体诗
Unity 3D 游戏引擎 Game Engine 游戏开发 计算机图形学 虚拟现实 Virtual Reality 程序设计 Programming