Hello there. My code is like that;
void Start () {
StreamWriter sr = File.CreateText(FILE_NAME);
sr.Close();
}
void Update () {
if (Input.GetMouseButtonDown (0) && EventSystem.current.currentSelectedGameObject == button1)
{
StreamWriter sr = File.OpenWrite (FILE_NAME);
sr.WriteLine ("You clicked on first button.");
sr.Close();
}
else if (Input.GetMouseButtonDown (0) && EventSystem.current.currentSelectedGameObject == button2)
{
StreamWriter sr = File.OpenWrite (FILE_NAME);
sr.WriteLine ("You clicked on second button.");
sr.Close();
}
}
My aim is basic actually. When I clicked on button it should be written on a Text file. I think I have a problem about opening and closing of text file. Because I got ‘Cannot implicitly convert type "System.IO.FileStream’ to ‘System.IO.StreamWriter’ " error.
What should I do now? Thanks in advance.