Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Execute external script

Discussion in 'Scripting' started by FennecMoon, Jul 7, 2019.

  1. FennecMoon

    FennecMoon

    Joined:
    Aug 12, 2015
    Posts:
    13
    I have a simple script that has "Hello World" displaying using OnGUI. I have uploaded this script to a site, and what I would like to do is have my project access the file, save it to my device, and then execute the saved file.

    I have been successful in accessing the file online, and writing it to my device (as a text file), but I cannot figure out how to execute the saved file. I have done many searches online, and I know I could just load the "Hello World" string as a variable, but I'm working on this being the method of updating my project, so I'm looking to be able to execute everything in the saved file. Right now it just says "Hello World" but tomorrow it may have an integer that counts down, or display 2 messages on GUI instead of 1, or any number of other things happening.

    Any help will be GREATLY appreciated.
     
  2. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    352
    I am not sure i completely understand but you might want to look into streamingAssets.
    https://docs.unity3d.com/Manual/StreamingAssets.html

    This will allow you to add a text file and read it I think. I know of its existence, but have not tried to use it.

    Edit: On topic of different parameters, you will have to convert most of the data manually and maybe do a TryParse for an integer.
     
  3. FennecMoon

    FennecMoon

    Joined:
    Aug 12, 2015
    Posts:
    13
    Thank you, I will look into that.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,798
    You can also use something like MoonSharp LUA to deliver LUA scripts to run in your game after it is compiled.

    Otherwise, generally all code has to be in at the moment the executable (or bundle in the case of asset stores like iOS and Android) is created. Code is not truly downloaded in an AssetBundle but rather there are links to use code already in your project at the time it was built.