0% found this document useful (0 votes)
13 views4 pages

Skill-Lab Report 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Skill-Lab Report 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to Unity

ARFoundation
1. Introduction
This project focuses on the process of developing an Augmented Reality (AR)
application using Unity's AR Foundation package and Google ARCore XR Plugin.
The app enables users to place a game asset onto a detected horizontal surface in
real-world environments using their mobile device's camera.

2. Step-by-Step Implementation

Step 1: Setting Up the Unity Project

1. Create a new 3D project in Unity.


2. Install the required packages via the Package Manager:
○ AR Foundation
○ Google ARCore XR Plugin
3. Set up the XR Plugin Management:
○ Go to Edit -> Project Settings -> XR Plugin
Management.
○ Enable ARCore under the Android tab.

Step 2: Configuring the Scene

1. Create an AR Session:
○ In the Hierarchy, add an AR Session game object.
2. Set Up XR Origin:
○ Add an XR Origin (AR) object from GameObject -> XR.
○ This handles AR tracking and alignment.
3. Add AR Components:
○ Select XR Origin and add:
■ AR Plane Manager
■ AR Raycast Manager
○ In AR Plane Manager, set Detection Mode to Horizontal.
○ Create an AR Default Plane prefab and assign it to the Raycast
Prefab field in the AR Raycast Manager.

Step 3: Writing the Placement Script

Create a C# script named [Link] and attach it to the XR


Origin object.

using [Link];

using UnityEngine;

using [Link];

using [Link];

public class PlaceObject : MonoBehaviour

public GameObject prefabObject;

bool isPlaneDetected = false;

ARRaycastManager arRay;

Pose objectPose;

void Start()

arRay = GetComponent<ARRaycastManager>();

// Update is called once per frame

void Update()

if(isPlaneDetected && [Link]>0 &&


[Link](0).phase == [Link])

{
PlacePrefab();

DetectPlane();

void PlacePrefab()

Instantiate(prefabObject,[Link],
[Link]);

void DetectPlane()

Vector3 screenCentre = [Link](new


Vector3(0.5f,0.5f,0f));

List<ARRaycastHit> hits = new List<ARRaycastHit>();

[Link](screenCentre,hits,[Link]);

isPlaneDetected = [Link]>0;

if(isPlaneDetected)

objectPose = hits[0].pose;

Step 4: Assigning Assets and Prefabs

1. Download a 3D asset (e.g., a character or object) from the Unity


Asset Store.
2. Create a prefab of the asset and assign it to the prefabObject field
in the PlaceObject script.
3. Attach the [Link] script to the XR Origin game object in
the Hierarchy.

Step 5: Building and Testing the Android App

1. Configure Unity for Android


○ Go to File → Build Settings → Android.
○ Click Switch Platform.
2. Enable AR Support
○ Go to Edit → Project Settings → XR Plugin Management.
○ Enable GoogleAR Core.
3. Build & Install the APK
○ Click Build.
○ Save the APK file and install it on an Android device.

You might also like