- Home /
 
               Question by 
               TSCSimulation_AH · Jan 30, 2019 at 03:45 PM · 
                c#applicationfocuslaunchexternal  
              
 
              Keeping Unity Focused
Hi guys, I'm trying to launch an external program via Unity, which I've achieved, but the focus gets stolen by the newly launched application. I want to - when it's been launched - to regain focus on Unity, but the code I've got keeps throwing an entry point exception. If you could help, that'd be great. Thanks!
Code:
 Process.Start(@"File path"); //Needs the full file path to launch.
 
                     Process[] prc = Process.GetProcessesByName("Unity");
                     if (prc.Length > 0)
                     {
                         currentActiveWindow = new IntPtr(GetActiveWindow());
                         currentActiveWindow = activeWindow;
                         try
                         {
                             SetForgroundWindow(prc[0].MainWindowHandle);
                         }
                         
                         catch(Exception)
                         {
                             UnityEngine.Debug.Log("It's not worked!");
                         }
                     }
 
                     warperIsRunning = true;
                 }
 
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Is there a way to detect when the game window has focus? 2 Answers
Teleport to next scene on trigger 1 Answer
Can I use a DLL in a iOS game? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                