Are you eager to delve into the world of Augmented Reality (AR) using Unity and Microsoft's AR Foundation? Setting up AR Foundation in Unity Learn can transform your gaming or application development journey, enabling you to create immersive AR experiences. This comprehensive guide will walk you through the process, ensuring you understand every step and are equipped to leverage AR Foundation's powerful features.

Before we begin, ensure you have Unity (2018.4 or later) installed on your computer, along with the AR Foundation package. If you haven't already, join Unity Learn's AR Foundation course to follow along with step-by-step guidance and resources.

Installing and Setting Up AR Foundation
AR Foundation is not installed by default in Unity, so let's start by adding it to your project.

1. Open your Unity project and go to Window > Package Manager to open the Package Manager window. Click on the 'Add package from git URL...' button.
Adding the AR Foundation Package

In the 'Add package from git URL...' field, paste the following URL and click 'Add':
https://github.com/Unity-Technologies/arfoundation.git#upm
Enabling AR Foundation

Once added, enable AR Foundation in your project. From the Project window, find 'XR Plug-in Management' and expand it. Check the box next to 'AR Foundation' to enable it.
Creating Your First AR Scene
Now that AR Foundation is set up, let's create a simple AR scene to get you started.

1. Go to File > New Scene to create a new scene. Rename it to something like 'AR Hello World' for ease of reference.
Adding the AR Session


![Button Animation (Using Animator) - Unity 3D[Tutorial][C#]](https://i.pinimg.com/originals/2b/39/46/2b394677b71af98f633162f63d517449.jpg)

















From the Unity hierarchy, delete the 'Main Camera' and 'Directional Light' objects since they won't be necessary for AR. Right-click in the hierarchy, navigate to 'UI > Panel' to add a 'Canvas' with a 'Raw Image' child object. This will serve as our AR view.
Next, drag 'AR Session' from the Project window (under 'AR Foundation > Prefabs') into the scene hierarchy. This prefab handles AR session management and provides essential functionality like device detection and session tracking.
Configuring the AR Camera and Main Camera
Select the 'Main Camera' in the hierarchy and delete it. Right-click in the hierarchy, navigate to 'AR Foundation > Cameras' and add 'AR Camera'. AR Camera is a customizable camera component designed for AR applications, providing better performance and functionality than the default Unity camera.
Now, create a new empty GameObject in the hierarchy and name it 'Camera Parent'. Add 'AR Camera' and 'AR Session' as children of 'Camera Parent'. This helps keep your hierarchy clean and organized.
Subject Tracking and Object Placement
AR Foundation provides several tracking methods, including plane detection, image tracking, and more. Let's focus on plane detection for simplicity, using it to place virtual objects in the real world.
Setting Up Plane Detection
AR Session includes a 'Plane Manager' component, which handles plane detection and mesh generation. Ensure it's enabled, as it is by default. For a better visual representation, add 'Plane Outline' prefab (AR Foundation > Prefabs) as a child of 'AR Session'.
Create an empty GameObject named 'Virtual Object Parent' in the hierarchy. This will serve as the parent for your virtual objects. For instance, add a 'Cube' prefab (Assets > Standard Assets > Utility > Cube) as a child of 'Virtual Object Parent'.
Spawning Virtual Objects
To spawn virtual objects, use AR Foundation's 'ARPlaceAtFollow' script. Add it to the 'Cube' object, and you'll see that it follows the AR session's plane detection and spawns the cube on the detected plane(s).
Testing Your AR Scene
To test your AR scene, ensure your device supports AR Foundation. If so, click the 'Play' button in Unity, build, and run your scene on your AR-capable device. You should see the detected planes and your 'Virtual Object Parent' spawning on them.
Congratulations! You've successfully set up AR Foundation in Unity and created your first AR scene. Explore Unity Learn's AR Foundation course for more advanced topics and continues learning. Happy AR developing!