Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[SOLVED] How can I create new c# scripts in the editor via code?

Discussion in 'Scripting' started by Deleted User, Jul 4, 2015.

  1. Deleted User

    Deleted User

    Guest

    Let's say when the user pushes a button, I want it to create a new c# script, and also dynamically edit code from a c# script by just clicking some buttons in the inspector. How can this be achieved?
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    System.IO.File.WriteAllText(path, string) to write script into a file, now all you need is to assemble the string from your desired script