I was struggling to find the fast android emulator for unity. I finally found the solution. I can use genymotion as the emulator. But the emulator needs to be configured little bit. I didn't know about this until I tried it. This solution works in my machine (Mac OSX 10.9.2). I haven't tried in windows machine. Here is what you have to do:
1. Download and install Genymotion. Here is how: https://cloud.genymotion.com/page/doc/#collapse4. The explanation is pretty straightforward. I assume you can install genymotion easily. After you successfully install genymotion, you should see this thing:
2. Add your virtual device emulator: https://cloud.genymotion.com/page/doc/#collapse5. Mine is Galaxy nexus - 4.1.1 - API 16 720x1280.
3. Run the emulator.
4. Now this is the tricky part. If you try to push .apk file to your emulator, it will show error message INSTALL_FAILED_CPU_ABI_INCOMPATIBLE. This is because Unity requires device that needs to support armv7 architechture. What you have to do is install the genymotion arm translation http://www.4shared.com/zip/4nRW7BS2ba/genymotion-arm-translation_v11.html. Just simply drag and drop the genymotion-arm-translation_v1.1.zip file to your emulator.
5. Restart your emulator.
6. Now, drag and drop your apk file to your emulator. This time it should work perfectly and it runs much faster than default android emulator.
Tuesday, June 3, 2014
Thursday, May 29, 2014
Unity Android back button problem
In my unity 4.3.4f1, the back button seems doesn't work. Sometimes, we want to make back button goes to the home screen or menu without exiting the application. There is a way to do this by simply calling android native code.
At first, we can use Input.GetKeyDown(KeyCode.Escape) to detect the back button input. I wrote the code inside update function:
// We also can write it in FixedUpdate function or whatever . The point is we want to check if the user press the back button
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
// Do your code here . . .
}
}
Now we want to execute what happens if user press the back button. Here is the common situation:
1. Quit the application
2. Go back to menu screen
At first, we can use Input.GetKeyDown(KeyCode.Escape) to detect the back button input. I wrote the code inside update function:
// We also can write it in FixedUpdate function or whatever . The point is we want to check if the user press the back button
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
// Do your code here . . .
}
}
Now we want to execute what happens if user press the back button. Here is the common situation:
1. Quit the application
2. Go back to menu screen
1. Quit the application
This is pretty straight forward. We can simply call Application.Quit();
2. Go back to menu screen
This is common if you want to build game for android. You can call the android native code to do this. Add a macro to make sure you run it in android.
// Inside "Do your code here . . ."
#if UNITY_ANDROID
// Get the unity player activity
AndroidJavaObject activity =
new AndroidJavaClass("com.unity3d.player.UnityPlayer")
.GetStatic<AndroidJavaObject>("currentActivity");
// call activity's boolean moveTaskToBack(boolean nonRoot) function
// documentation:
http://developer.android.com/reference/android/app/Activity.html#moveTaskToBack(boolean)
http://developer.android.com/reference/android/app/Activity.html#moveTaskToBack(boolean)
activity.Call<bool>("moveTaskToBack", true);
#endif
activity.Call<bool>("moveTaskToBack", true); The method signature is it takes parameter boolean and it returns boolean. So our call function signature must match the moveTaskToBack signature.
activity.Call<bool>("moveTaskToBack", true); The method signature is it takes parameter boolean and it returns boolean. So our call function signature must match the moveTaskToBack signature.
Introduction
Hello, my name is Adhika. I like to be called Jacky.
In this blog, I would like to post any thoughts, problem, or anything related to unity game development. Hopefully it is useful for some of you out there who has the same problem with me.
In this blog, I would like to post any thoughts, problem, or anything related to unity game development. Hopefully it is useful for some of you out there who has the same problem with me.
Subscribe to:
Posts (Atom)