Can you have a script write a script?

I wish to make a program similar to Watson using Unity and I feel this is one of the first steps.

Although I feel like this question should be much more precise (Watson the IBM computer? What should the script do? etc…) here’s a general answer:

Creating a script from within another script is called ‘code generation’ and it’s used as a tool within Unity and all around different software. The simplest form would be to just have a code create a string a write it to a text file like this:

using UnityEngine;

public class CodeGenerator : MonoBehaviour 
{
	void Start()
	{
		string s = "";

		s += "using UnityEngine;

";
s += "public class MyMonoBehaviour : MonoBehaviour{
";
s += " void Start(){
";
s += " Debug.Log("Hello World!");
";
s += " }
}
";

		System.IO.File.WriteAllText(Application.dataPath + "/MyMonoBehaviour.cs", s);
	}
}

But this of course becomes very tedious. There are a couple of libraries or different solutions to help generate code. One for example is the CodeDOM class in the .NET framework. It helps you create classes and objects in a syntax tree (tell it the meaning of something, not the actual code) and then writes the string for you.