Get Started with AR in Unity in 6 minutes!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
ar foundation is an awesome unity package that allows you to create augmented reality apps with ar core for android ar kit for ios and pretty much every other major augmented reality platform that there is today i'll show you how to get started on your journey creating amazing augmented reality apps i'm using unity 2020.2 but using a future version should be fun inside unity let's make sure our build settings are set to the device we want i'm using android so i'll select that next i'll click on switch platform we should now go to the package manager and open the unity registry next install ar foundation from the registry list also install ar core and or ar kit depending on your platform let's go to project settings and open xr plugin management navigate to mobile settings to set the development kit for ar core for android if you're using ios as far as i know you don't have to do this step if you chose universal render pipeline when starting your project there's one thing you have to do go to graphics and open your scriptable render pipeline settings with a double click then you double-click your renderer data click the plus sign to add renderer features choose the ar1 great now we can close all of that and finally get to our scene right click the hierarchy and create a new ar session the ar session class controls the augmented reality configuration options while our app is open next let's add an ar session origin the session origin is used to convert session space to unity's world space basically it's like the zero zero zero of the current scene inside the session origin you'll see that unity has also given us an ar camera which will represent your phone device this position of your phone will be relative to the ar session origin so we're going to want to find planes in our scene first you want to add the ar plane manager the plane manager creates game objects for each detected plane in the environment let's create an ar default plane by right-clicking the hierarchy and going to xr again now just add that plane to the plane prefab slot in the ar plane manager this is going to allow us to visualize planes that are detected by our phone like i did in the intro app we want to place some objects in the scene so we'll need an ar raycast manager on our ar session origin as well so we can detect the planes we are clicking create a new game object called ar cursor for the cursor i quickly created an image in photoshop you can download from the link in the description or you can create your own change the image texture type to 2d you should make this a child of ar cursor then set the rotation on the x-axis to 90 so it can lay flat also scale it down to 0.25 on the x y and z create a new script called ar cursor on the parent create a game object for the cursor child object create a game object for the object you want to place create another member variable for the raycast manager in the unity editor let's fill in those member variable slots a our cursor child object let's create a random capsule and set it to 0.25 f for our object to place make the capsule a prefab and drag it to the object to play slot let's drag the raycast manager as well back to the script let's create a member variable called use cursor this will be used to turn on and off the cursor being visualized in the start let's set the cursor child object to active depending on if the used cursor is true or false in the update let's call update cursor if use cursor is true create the method update cursor as a void we need to get a screen position to set our cursor to and we can do that with viewport to screen point using the middle point of the screen 0.5 is the halfway between the max size of one now we're going to raycast to detect the planes that our cursor is touching create a list for ar raycast hit then call raycast using raycast manager pass in the screen position hits and trackabletype.plane to indicate we only want to detect planes if the hit count is greater than zero let's set the transform position to hits zero dot pose dot position and let's set the rotation to hits 0.pose.rotation we should test it out when we run our android app we can see planes being generated and our cursor is hovering above those planes using our raycast detection let's place our object first check to see if the screen was touched with the input system also we need to make sure this is the beginning of a touch and not the user simply holding down a touch again let's check if we are using a cursor if the cursor is true then we're done just instantiate the object at the current position and rotation of our cursor else if we have our cursor off and want to place the object where we touch let's do another raycast at the touch position if the hit count is greater than zero instantiate the object at the hit position remember to turn off use cursor and now you can place the object wherever you want if the video helped you remember to leave a like and if you have some other ar tutorial ideas that i should do leave a comment below and i'll consider making a video for that thanks a lot [Music]
Info
Channel: Novaborn
Views: 30,869
Rating: undefined out of 5
Keywords: how to make an augmented reality game in unity, ar unity game, ar in unity, unity ar for beginners, unity ar getting started, get started with ar, unity ar tutorial, augmented reality tutorial, augmented reality tutorial for beginners, getting started with ar, how to get into ar, how to learn augmented reality, unity ar, ar foundation unity, ar foundation basics, arcore unity, arkit, arcore, arkit tutorial, unity ar foundation tutorial, arkit unity, unity ar object placement
Id: R3OCUE9TwZk
Channel Id: undefined
Length: 6min 59sec (419 seconds)
Published: Tue Mar 09 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.