title: How to generate a non-existing C# script programatically in Unity3D
body: <p><strong>How to generate or create a non existing script (preferably C#)?</strong></p>
  
  <p>It is always time consuming and tiring for me to create the methods for my object's animations.</p>
  
  <p>So I am planning to create a custom <code>Editor</code> where I can just refer the <code>GameObject</code> with <code>Animation</code> component, enter a name for the script to be generated then click a button to automatically generate a C# script with methods that plays the animations of that object.</p>
  
  <p>I was wondering if there's a way to make a string and assign the code needed to that string then turn it into a C# script.</p>
  
  <p>I have read on <code>AssetDatabase</code> and <code>Monoscript</code> about create an Asset but still no luck.</p>
  
  <p>There's no problem with attaching the generated script to a <code>GameObject</code>.</p>
  
  <p>Thank you.</p>
  
  <p><strong>[Update]</strong>
  Additional Information
  <img src="https://i.stack.imgur.com/N2X5Q.png" alt="This is my animations"></p>
  
  <p>So based to this component, I want to generate a C# script that has the methods of playing each animation like this..</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public class Level3TerrainB : MonoBehaviour {
  
      private string animationPrefix = "arm_Root_PlatformB|anim_";
  
      public void AnimatePressButtonA() {
          animation.Blend (animationPrefix + "PressButtonA");
      }
  
      public void AnimateUnpressButtonA() {
          animation.Blend (animationPrefix + "UnpressButtonA");
      }
  
      public void AnimatePressButtonB() {
          animation.Blend (animationPrefix + "PressButtonB");
      }
  
      public void AnimateUnpressButtonB() {
          animation.Blend (animationPrefix + "UnpressButtonB");
      }
  
      public void AnimateUpButtonB() {
          animation.Blend (animationPrefix + "UpButtonB");
      }
  
      public void AnimateDownButtonB() {
          animation.Blend (animationPrefix + "DownButtonB");
      }
  
      public void AnimatePressButtonC() {
          animation.Blend (animationPrefix + "PressButtonC");
      }
  
      public void AnimateUnpressButtonC() {
          animation.Blend (animationPrefix + "UnpressButtonC");
      }
  
      public void AnimateUpButtonC() {
          animation.Blend (animationPrefix + "UpButtonC");
      }
  
      public void AnimateDownButtonC() {
          animation.Blend (animationPrefix + "DownButtonC");
      }
  
      public void AnimatePressButtonD() {
          animation.Blend (animationPrefix + "PressButtonD");
      }
  
      public void AnimateUnpressButtonD() {
          animation.Blend (animationPrefix + "UnpressButtonD");
      }
  
      public void AnimateLeftUpPulleyA() {
          animation.Blend (animationPrefix + "LeftUpPulleyA");
      }
  
      public void AnimateRightUpPulleyA() {
          animation.Blend (animationPrefix + "RightUpPulleyA");
      }
  
      public void AnimateLeftUpPulleyB() {
          animation.Blend (animationPrefix + "LeftUpPulleyB");
      }
  
      public void AnimateRightUpPulleyB() {
          animation.Blend (animationPrefix + "RightUpPulleyB");
      }
  
  }
  </code></pre>
  
  <p>I don't want to hard code it again, and again.. because I have many other levels to animate to.</p>