- Home /
Desktop Game & More
This could be a stupid question but with All the power that unity has is it possible to create a game/utility that would be able to run and make external commands to windows... ie shoot a crate and launch explorer... open a door launch an application.. then return to our game/utility afterwards?? Of course I am way out of my depth at creating such a venture anyway but I thought if I want to learn jump in at the deep end
Answer by Cyclops · Mar 15, 2010 at 02:35 PM
Update - yes you can, if you're building a standalone executable, and no, it does not require Unity Pro. :) Here is a C# example that starts Notepad:
using System;
using System.Diagnostics;
void Start () {
String path = @"f:\temp\data.txt";
Process foo = new Process();
foo.StartInfo.FileName = "Notepad.exe";
foo.StartInfo.Arguments = path;
foo.Start();
}
Here's another example that opens a file and writes a line:
using System; using System.IO; using System.Text;
void Start () { String path = @"f:\temp\data.txt"; FileStream bar = File.Create(path); byte[] data = new UTF8Encoding(true).GetBytes(path); bar.Write(data, 0, path.Length); bar.Close(); }
So basically, anything that the the Unity version of .NET can do, a standalone program can do.
[obsolete] No, it's not a stupid question, it would be a nice feature, but... Shoot a crate, launch a virus - Open a door, write a password keylogger file... The possibilities are endless - which is why the possibilities are limited. :) Because it runs in a Browser window, there are security restriction on what Unity can do. Which includes not being able to access files on the local system. (I'm not sure about the standalone executable version).
There's a reference to being able to save player data at: Game External Files.
Also, if you want to learn Unity (possibly starting at the shallow end :), some more Answers are:
Start Learning Unity... and Scripting...
You will be scripting if you want to use Unity. :)
And - please read the FAQ
Update - as Eric5h5 point out, this only applies to a Browser build. If you want to do a stand-alone executable file, then yes, you can do all of those things. Unity has full access to .NET, which means you call open/close files, make system calls, do anything the Win32 API can do.
Odd - there wasn't a security tag already. Well, now there is. :)
Unity doesn't run in a browser window unless you make a web build. If the question is about stand-alone apps, which I'm pretty sure it is, then none of the browser security restrictions apply.
$$anonymous$$inor note - in Javascript, it would be import System.Diagnostics; ins$$anonymous$$d of C# using statement.
Answer by Eric5h5 · Mar 29, 2010 at 04:09 PM
Yes, you can do those things. Using Unity Pro, you can write plugins that do anything you like. There may be other ways of launching external applications without Pro, but I'm not familiar with them offhand.
Your answer
Follow this Question
Related Questions
What are the package dependencies for Unity Linux Player? 1 Answer
Touch inputs on a Desktop type device 2 Answers
Editor utility for handling nested prefabs.. 4 Answers
Security Sandbox on the webplayer 3.0 1 Answer
Security for sensitive data 2 Answers