I copied and pasted a script into my script and edited it to be my own, and I got this error while trying to drag it onto a game object:
The Script Needs to Derive from MonoBehavior!
I would simply like to know how to fix it. I did a little research on it, and found everything out about it other than to fix it xD. Here’s my code:
using System;
using System.IO;
using System.Text;
public class ServerCreate : MonoBehaviour
{
void Start()
{
string path = @"c:\bgriley\Desktop\MyTest.txt";
try
{
// Delete the file if it exists.
if (File.Exists(path))
{
// Note that no lock is put on the
// file and the possibility exists
// that another process could do
// something with it between
// the calls to Exists and Delete.
File.Delete(path);
}
// Create the file.
using (FileStream fs = File.Create(path))
{
Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file.");
// Add some information to the file.
fs.Write(info, 0, info.Length);
}
// Open the stream and read it back.
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
}
catch (Exception Ex)
{
Console.WriteLine(Ex.ToString());
}
}
}
Thanks