Develop a 3D Mobile App in Unity
Screenshot of a game you can make in Unity using these useful mobile optimization tips and tricks.

Develop a 3D Mobile App in Unity

Goal: Make a 60+ fps, VR-compatible, Unity game using minimal code... GO!

Finished Product: Google Play Store link

To make a simple 3D mobile game, everything but the bare basics must be stripped away. Mobile devices are limited in processing, graphics, and screen space. Therefore, creating a good-looking and smooth-running game is quite a challenge for the those unfamiliar with the "nitty-gritty" of game engines. For instance, we're looking at kilobytes instead of megabytes for textures, little to no post-processing effects(motion blur, color correction, etc.), and overly-simplified physics for starters.

Here are some tips/tricks I found useful when creating my own mobile game.


Setting Up the Player Object

A simple player object consists of a camera, a physics collider, and a light source (for a flashlight).

To play the game, the player needs to be able to move and look around. In the example, I use an onscreen joystick and the device's accelerometer to move the player and the camera.

Joystick

The onscreen joystick was created following this YouTube tutorial. Download the C# script used, here.

Camera Accelerometer

The camera movement is controlled by this JavaScript script that reads the accelerometer data of the device and rotates/tilts the camera accordingly. This script also works when exporting for VR(Oculus, Cardboard, Gear, etc.).

Camera Settings

Change the clipping plane property of the camera so that the far value is as small as possible. This decreases how far the camera renders at any given moment. An easy way to hide this effect is to add fog to blend the clipping to black. (I'm using radial fog—not the built-in distance based one.)


Setting Up an Optimized Game World

  • Set Objects to Static. Set non-moving objects to static. We'll see a setting later that combines static meshes to optimize performance.
  • Mesh Compression. When importing models, set mesh compression to high to allow Unity to optimize the mesh. Overall, this will decrease the triangles/polys rendered every frame.
  • Compress Textures. Resize textures to be as small as possible. All textures in the example are under 800kb, such as the walls, floor, and timber. Also, remove all but the albedo texture. Rendering normal maps puts additional strain on the device.
  • Eliminate Mesh Colliders. (Optional) Mesh colliders are what Unity creates to enable physics on objects of unique shape and size. Using them on mobile is not recommended. I recreated all the colliders with box colliders instead and this helped the terrain render with a much higher FPS. If physics is is taking up a large percentage in the profiler, this may help. However, this step may take too much time depending upon the complexity of the scene.


Build Settings

Lastly, the build settings of your project should look something like this.

  • Pixel Light Count and Texture Quality should be as low as acceptable.
  • Anisotropic Textures and Anti Aliasing should both be disabled along with Soft Particles and Realtime Reflection Probes.
  • Shadows should be set to hard or off completely, at the lowest acceptable resolution, and with a limiting distance similar to the clipping plane distance.


Scripts Used

To create the game, several simple and reusable scripts were utilized on a plane with a box collider set to "Is trigger".

  1. A jumpscare script can be used so that when the player walks through it, a sound clip is played and another GameObject/Light appears. The tutorial can be found on YouTube here, and the added functionality for lights can be downloaded here "JumpScareTrigger.js".
  2. A show object on trigger script to show an object(s) when the player triggers it. Download "GameObjectShow.cs" here.
  3. A hide object on trigger script to hide an object(s) when the player triggers it. Download "GameObjectHide.cs" here.
  4. A text display script, to show text onscreen after being triggered, Requires a Text object present and attached to a Canvas object. Download "TextTrigger.cs" here.
  5. An explode timer script was used twice to enable explosion sound effects, explosion particles, lights, exploded objects, and camera effects. Download "ExplodeTimer.cs" here. (As seen below)


And that's it; plug your phone in, click Build and Run and watch it start up on your device. If you feel like I should add more on a specific section or if you know of any other good resources for creating and learning Unity quickly, feel free to comment.

Download from the Google Play Store here: https://play.google.com/store/apps/details?id=com.adamkehl.thehouse

Thanks for reading!

要查看或添加评论,请登录

社区洞察

其他会员也浏览了