Lesson 2: Unity Mobile Project Setup
Welcome back, mobile game developer! In this lesson, you'll transform your game concept into a properly configured Unity project that's optimized for mobile devices. By the end of this lesson, you'll have a solid foundation that's ready for touch controls, mobile-specific optimizations, and puzzle game mechanics.
What You'll Learn
- Configure Unity for mobile development
- Set up proper project structure for puzzle games
- Implement mobile-specific settings and optimizations
- Create responsive touch controls foundation
- Establish mobile UI framework
Prerequisites
- Unity 2022.3 LTS or newer installed
- Basic understanding of Unity interface
- Completed Lesson 1: Mobile Game Concept & Market Research
Step 1: Create New Unity Project
Let's start by creating a new Unity project specifically optimized for mobile puzzle games:
- Open Unity Hub and click "New Project"
- Select Template: Choose "2D Core" template (perfect for puzzle games)
- Project Name:
MobilePuzzleGame(or your preferred name) - Location: Choose a dedicated folder for your project
- Unity Version: Use Unity 2022.3 LTS or newer for stability
Pro Tip: Always use LTS (Long Term Support) versions for production projects. They're more stable and receive longer support.
Step 2: Configure Mobile Build Settings
Before we start developing, let's configure Unity for mobile deployment:
- Open Build Settings: File → Build Settings
- Switch Platform: Select "Android" or "iOS" (choose your target platform)
- Player Settings: Click "Player Settings" button
- Configure Company Name: Set to your studio name
- Product Name: Set to your game name
- Version: Start with "0.1.0" for development
Android-Specific Settings
If targeting Android:
- Minimum API Level: Set to Android 7.0 (API level 24) for broad compatibility
- Target API Level: Use latest stable version
- Scripting Backend: IL2CPP for better performance
- Architecture: ARM64 for modern devices
iOS-Specific Settings
If targeting iOS:
- Target iOS Version: iOS 12.0 or newer
- Architecture: ARM64
- Scripting Backend: IL2CPP
Step 3: Mobile-Optimized Project Structure
Create a clean, organized folder structure in your Project window:
Assets/
├── Scripts/
│ ├── Core/
│ ├── UI/
│ ├── Puzzle/
│ └── Mobile/
├── Art/
│ ├── Sprites/
│ ├── UI/
│ └── Backgrounds/
├── Audio/
│ ├── Music/
│ ├── SFX/
│ └── Voice/
├── Prefabs/
│ ├── Puzzle/
│ ├── UI/
│ └── Mobile/
├── Scenes/
│ ├── MainMenu/
│ ├── Gameplay/
│ └── Settings/
└── Resources/
├── Mobile/
└── Config/
Mini-Task: Create this folder structure in your Unity project. Right-click in the Project window and create folders as needed.
Step 4: Mobile-Specific Settings Configuration
Configure Unity settings for optimal mobile performance:
Quality Settings
- Open Quality Settings: Edit → Project Settings → Quality
- Mobile Quality: Select "Simple" or "Fast" quality level
- Texture Quality: Set to "Half Res" for better performance
- Anti Aliasing: Disable or use "2x Multi Sampling"
- Soft Particles: Disable for better performance
Player Settings Optimization
- Open Player Settings: Edit → Project Settings → Player
- Resolution and Presentation:
- Default Screen Width: 1080
- Default Screen Height: 1920
- Default Screen Orientation: Portrait (for puzzle games)
- Publishing Settings:
- Company Name: Your studio name
- Product Name: Your game name
- Version: 0.1.0
Graphics Settings
- Open Graphics Settings: Edit → Project Settings → Graphics
- Scriptable Render Pipeline: Use Built-in Render Pipeline for simplicity
- Shader Stripping: Enable for smaller build sizes
Step 5: Touch Input System Setup
Set up the foundation for touch controls:
- Create Input Manager: Create empty GameObject named "InputManager"
- Add Input Script: Create new C# script called
MobileInputManager.cs
using UnityEngine;
public class MobileInputManager : MonoBehaviour
{
public static MobileInputManager Instance { get; private set; }
[Header("Touch Settings")]
public float touchSensitivity = 1.0f;
public float tapThreshold = 0.2f;
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
private void Update()
{
HandleTouchInput();
}
private void HandleTouchInput()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
switch (touch.phase)
{
case TouchPhase.Began:
OnTouchStart(touch.position);
break;
case TouchPhase.Moved:
OnTouchMove(touch.position, touch.deltaPosition);
break;
case TouchPhase.Ended:
OnTouchEnd(touch.position);
break;
}
}
}
private void OnTouchStart(Vector2 position)
{
// Handle touch start
Debug.Log($"Touch started at: {position}");
}
private void OnTouchMove(Vector2 position, Vector2 deltaPosition)
{
// Handle touch movement
}
private void OnTouchEnd(Vector2 position)
{
// Handle touch end
Debug.Log($"Touch ended at: {position}");
}
}
- Attach Script: Add the script to the InputManager GameObject
Step 6: Mobile UI Canvas Setup
Create a responsive UI system for mobile devices:
-
Create UI Canvas: Right-click in Hierarchy → UI → Canvas
-
Canvas Settings:
- Render Mode: Screen Space - Overlay
- UI Scale Mode: Scale With Screen Size
- Reference Resolution: 1080 x 1920 (portrait)
- Screen Match Mode: Match Width Or Height
- Match: 0.5 (balanced scaling)
-
Add Canvas Scaler: The Canvas Scaler component should be automatically added
-
Create UI Panels: Add child GameObjects for different UI sections:
- MainMenuPanel
- GameplayPanel
- SettingsPanel
- PausePanel
Step 7: Mobile-Specific Optimizations
Implement mobile performance optimizations:
Frame Rate Control
using UnityEngine;
public class MobilePerformanceManager : MonoBehaviour
{
[Header("Performance Settings")]
public int targetFrameRate = 60;
public bool enableVSync = true;
private void Start()
{
// Set target frame rate
Application.targetFrameRate = targetFrameRate;
// Enable VSync for smoother gameplay
QualitySettings.vSyncCount = enableVSync ? 1 : 0;
// Optimize for mobile
OptimizeForMobile();
}
private void OptimizeForMobile()
{
// Disable unnecessary features
QualitySettings.shadowDistance = 50f;
QualitySettings.shadowResolution = ShadowResolution.Low;
QualitySettings.shadowCascades = 1;
// Optimize rendering
QualitySettings.particleRaycastBudget = 256;
QualitySettings.maxQueuedFrames = 2;
}
}
Memory Management
using UnityEngine;
public class MobileMemoryManager : MonoBehaviour
{
private void Start()
{
// Set memory limits
Application.targetFrameRate = 60;
// Enable garbage collection optimization
System.GC.Collect();
}
private void OnApplicationPause(bool pauseStatus)
{
if (pauseStatus)
{
// Pause game and free memory
Time.timeScale = 0f;
System.GC.Collect();
}
else
{
// Resume game
Time.timeScale = 1f;
}
}
}
Step 8: Create Basic Scene Structure
Set up your first game scene:
-
Create New Scene: File → New Scene → 2D
-
Save Scene: Save as "Gameplay" in Scenes folder
-
Add Essential Objects:
- Main Camera (configured for mobile)
- InputManager (with MobileInputManager script)
- PerformanceManager (with MobilePerformanceManager script)
- UI Canvas (with mobile-optimized settings)
-
Camera Configuration:
- Size: 5 (adjust based on your game's needs)
- Position: (0, 0, -10)
- Clear Flags: Solid Color
- Background: Choose a pleasant color for your puzzle game
Step 9: Mobile Testing Setup
Prepare for mobile testing:
- Build Settings: Add your scene to Build Settings
- Development Build: Enable "Development Build" for debugging
- Script Debugging: Enable "Script Debugging" for breakpoints
- Connect Device: Connect your Android/iOS device via USB
- Build and Run: Test on actual device for accurate performance
Mini-Challenge: Create Mobile Interface
Your challenge is to create a basic mobile interface for your puzzle game:
-
Create Main Menu: Design a simple main menu with:
- Game title
- Play button
- Settings button
- Exit button
-
Implement Touch Controls: Make buttons respond to touch input
-
Test on Device: Build and test on your mobile device
-
Optimize Performance: Ensure smooth 60 FPS gameplay
Troubleshooting Common Issues
Issue: Game runs slowly on mobile
Solution:
- Reduce texture quality in Quality Settings
- Disable unnecessary visual effects
- Lower target frame rate to 30 FPS if needed
- Use object pooling for frequently created/destroyed objects
Issue: Touch input not responsive
Solution:
- Check Input Manager settings
- Ensure UI elements have proper colliders
- Verify touch sensitivity settings
- Test on actual device (not just editor)
Issue: UI elements too small/large on different devices
Solution:
- Use Canvas Scaler with Scale With Screen Size
- Set proper reference resolution
- Test on multiple device sizes
- Use relative positioning instead of absolute
Pro Tips for Mobile Development
- Always Test on Device: The Unity editor doesn't accurately represent mobile performance
- Optimize Early: Don't wait until the end to optimize - it's much harder then
- Use Profiler: Unity's Profiler is essential for finding performance bottlenecks
- Consider Battery Life: Avoid unnecessary calculations and rendering
- Handle Interruptions: Implement proper pause/resume functionality
What's Next?
Congratulations! You've successfully set up a mobile-optimized Unity project. In the next lesson, you'll dive into creating the art pipeline and designing mobile-optimized assets for your puzzle game.
Next Lesson Preview: "Lesson 3: Mobile Art Pipeline" - You'll learn how to create scalable, mobile-optimized art assets and establish an efficient art workflow.
Key Takeaways
- Mobile development requires specific Unity configurations
- Touch input systems need careful implementation
- Performance optimization is crucial from the start
- Testing on actual devices is essential
- Proper project structure saves time later
Community & Support
- Share Your Setup: Post screenshots of your project structure in our Discord community
- Get Feedback: Ask for feedback on your mobile interface design
- Join Mobile Dev Channel: Connect with other mobile game developers
- Ask Questions: Use the #mobile-development channel for technical help
Remember, mobile game development is a marathon, not a sprint. Take your time to set up a solid foundation, and you'll save hours of debugging later!
Ready to create beautiful mobile art assets? Let's move on to Lesson 3: Mobile Art Pipeline!