Linking button click in windows form app to a game in unity

Viewed 222

I am making a project in which i want to open and start a game in unity when a button is clicked on a windows form app. So is there a solution for this problem?

3 Answers

I'm assuming that you know how to build it: https://docs.unity3d.com/Manual/PublishingBuilds.html

So you need to do 3 (one optional) things:

  1. Create an ex executable file. The publish method mentioned above will do that for you
  2. (Optional) use a packaging software to create installer. Check the unity forums for one of these
  3. Run the executable from windows forms: using windows forms execute a .exe file
void btnButton_Click(object sender, EventArgs e)
{
    Process.Start("cmd.exe", "/k C:\path_to_game\start.exe")
}

You can use the Process class to bootstrap a new process:

Process.Start(@"D:\GameLocation\game.exe");

This, of course, hinges on the assumption that you have already built the game, and have an executable that you can call.

private void Button1_Click(object o, EventArgs eA)
{
Process.Start("C:\\my_unity_game_location\mygame.exe");
}

Here Button1 is the button which is present on your WinForm and Button1_Click is the event which is assigned to that Button1

Related