Creating a Cup Game Using Unity for AR and VR 2025 – Creating a cup game using Unity software for both AR and VR is a great way to dive into immersive technologies.
The Cup Game is an interactive game where you pick up and drop a virtual cup using AR (Augmented Reality) on your phone or VR (Virtual Reality) with a headset. In AR, the cup appears in your real-world environment on the screen, while in VR, you use controllers to interact with the cup in a virtual world. It’s a fun and simple way to explore AR/VR technology!

Title:
Creating a Cup Game Using Unity for AR & VR
Theory:
Augmented Reality (AR) and Virtual Reality (VR) are two powerful technologies that create immersive experiences.
- Augmented Reality (AR) blends the real world with virtual objects, letting you interact with both simultaneously using devices like smartphones, tablets, or AR glasses.
- Virtual Reality (VR), on the other hand, completely immerses the user in a virtual environment through VR headsets like Oculus Rift, HTC Vive, or PlayStation VR.
By creating a cup game, where users place virtual cups on real or virtual tables, they get to experience how these technologies work in a hands-on and fun way.
The cup game can be built in Unity using both AR and VR modes, allowing users to interact with virtual cups in a 3D space.
Requirements:
1. Software:
- Unity (Free or Pro version)
- AR Foundation (for AR support)
- XR Interaction Toolkit (for VR support)
- Vuforia (for AR, optional)
- Visual Studio (for scripting)
2. Hardware:
- For AR: Smartphone or tablet with AR capabilities (e.g., iPhone or Android device with ARCore or ARKit)
- For VR: VR headset (e.g., Oculus Quest, HTC Vive, or similar) and controllers
3. Assets:
- 3D models of cups and tables (you can download free models from the Unity Asset Store)
- Textures for the cups (optional, to make it look realistic)
- Sound effects (optional, for more immersive experience)
Creating a Cup Game Using Unity for AR and VR 2025
How to Set Up the Cup Game in Unity (AR & VR)
1. Start a New Project in Unity:
- Open Unity and create a new 3D project. This is where your cup game will live.
2. Install What You Need:
For the game to work, we need some tools (called packages) in Unity. These tools help the game work in AR and VR.
- For AR (Augmented Reality):
- Go to Window > Package Manager.
- In the Unity Registry, search for AR Foundation and click Install.
- Then, install ARKit (for iPhones) or ARCore (for Android phones). This will allow your phone to detect surfaces like tables in the real world.
- For VR (Virtual Reality):
- Go to Window > Package Manager.
- In the search bar, type XR Interaction Toolkit and install it. This helps you create interactive VR experiences.
3. Create the Cup:
Now, we need to create a 3D cup that we can interact with in AR and VR. Here’s how to do it:
- In Unity, create a 3D model of a cup. You can use a simple cylinder to make a cup shape. Just right-click in the Hierarchy and choose 3D Object > Cylinder.
- Add a Rigidbody (this makes the cup react to gravity) and a Collider (this makes the cup detect when it touches something) to the cup.
4. Set Up the Scene for AR and VR:
For AR:
- In the Hierarchy, right-click and create an AR Session and AR Session Origin.
- Inside the AR Session Origin, add an AR Camera (this replaces the normal camera and lets us see AR).
- Add the ARSetup.cs script to the AR Session Origin.
- The script will allow you to place cups on real surfaces, like tables, when you tap on the screen.
For VR:
- If you’re using XR Interaction Toolkit, right-click and create an XR Rig. This will act as your VR player.
- Set up a virtual table where the cups will be placed. This is just a 3D object (like a flat cube).
- Add the VRSetup.cs script (the one I provided) to the XR Rig.
- The script allows the VR controller to grab and place the cup.
5. Connect Everything:
Now, we need to link everything together so it works in the game.
- AR Setup: In the Inspector, drag the AR Camera to the arCamera field in the script. Then, drag the Cup Prefab to the Cup Prefab field.
- VR Setup: In the Inspector, link the Cup Prefab to the script so that it can be picked up in VR.
1. CupInteraction.cs (Core Interaction Script)
This script handles the picking up and dropping of the cup in both AR and VR scenarios.
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
public class CupInteraction : MonoBehaviour
{
private bool isPickedUp = false;
private XRGrabInteractable grabInteractable;
// Reference to the AR interaction if needed
public GameObject arCamera;
void Start()
{
// Check if this is VR or AR environment
grabInteractable = GetComponent<XRGrabInteractable>();
if (arCamera != null)
{
// For AR, use this as a reference to attach the cup to.
grabInteractable.enabled = false; // Disable VR grab for AR
}
else
{
grabInteractable.enabled = true; // Enable VR grab
}
}
// For VR and AR Interaction:
public void OnInteract()
{
if (!isPickedUp)
{
// For VR: Attach to controller, for AR: attach to AR camera
if (arCamera != null)
{
transform.SetParent(arCamera.transform); // Attach to the AR camera
transform.localPosition = new Vector3(0, 0, 0.5f); // Position it in front of the player
isPickedUp = true;
}
else
{
// For VR: The XR Interaction Toolkit manages this automatically
isPickedUp = true;
}
}
else
{
// Drop the cup in both VR and AR
transform.SetParent(null); // Detach from parent (camera or controller)
isPickedUp = false;
}
}
// Called when the VR controller interacts with the cup
public void OnGrab()
{
OnInteract();
}
// Called when the cup is released
public void OnRelease()
{
OnInteract();
}
}
Explanation:
- The script uses the XR Interaction Toolkit for VR and AR. The
XRGrabInteractable
component is used for VR interaction, and for AR, the cup is attached to the AR camera when picked up. - For AR: It uses the AR camera to attach the cup, so it appears as if the cup is held in the player’s hand.
- For VR: The XR toolkit handles the interaction and grabbing automatically.
2. AR and VR Camera Setup
AR Setup:
- Create a new empty GameObject and name it
AR Session
. - Add the
AR Session
andAR Session Origin
from AR Foundation. - Attach an AR Camera from the AR Foundation package to the
AR Session Origin
. - Ensure the AR Camera is set to the camera that will interact with the AR environment.
VR Setup:
- Create an empty GameObject called
XR Rig
from the XR Interaction Toolkit. - Add the
XR Camera
prefab inside theXR Rig
. - Assign your VR controller to the XR Interaction Toolkit, which automatically handles input and grabbing.
3. Interaction via Button in AR (UI for AR)
If you want to simulate interaction in AR (by tapping the screen), you can create a simple button to simulate picking up the cup.
AR Interaction Script:
using UnityEngine;
using UnityEngine.UI;
public class ARButtonInteraction : MonoBehaviour
{
public GameObject cup; // The cup you want to pick up
public Button interactButton;
void Start()
{
// Assign button click event
interactButton.onClick.AddListener(OnButtonPress);
}
void OnButtonPress()
{
// Call the cup interaction method
cup.GetComponent<CupInteraction>().OnInteract();
}
}
Instructions for AR Button Setup:
- Create a UI canvas (
UI > Canvas
) in your scene. - Add a Button inside the canvas.
- Drag this
ARButtonInteraction
script onto any object in your scene. - Assign the cup GameObject and the button in the inspector.
This script will allow you to simulate the interaction (picking up and dropping the cup) by tapping a button in AR.
4. Setting up AR/VR Interaction for Cup Game
- Ensure that you have attached the XRGrabInteractable component to the cup (for VR).
- For AR, when the user taps the screen (using the AR button or screen touch), the cup will attach to the AR camera.
5. Additional Features
Sound Effects:
To add sound effects for picking up and dropping the cup, you can modify the OnInteract()
function to play audio:
public AudioClip pickUpSound;
public AudioClip dropSound;
private AudioSource audioSource;
void Start()
{
audioSource = GetComponent<AudioSource>();
}
public void OnInteract()
{
if (!isPickedUp)
{
audioSource.PlayOneShot(pickUpSound); // Play sound when picked up
// Attach cup logic...
}
else
{
audioSource.PlayOneShot(dropSound); // Play sound when dropped
// Detach cup logic...
}
}
- Attach the
AudioSource
component to the cup. - Assign your pick-up and drop sounds in the inspector.
Score Tracking:
You can also add a simple scoring system that tracks how many times the player picks up the cup.
public class GameManager : MonoBehaviour
{
public Text scoreText; // UI Text to display score
private int score = 0;
public void IncreaseScore()
{
score++;
scoreText.text = "Score: " + score.ToString();
}
}
- Call
IncreaseScore()
each time the player picks up the cup.
What Will Happen:
- In AR: You’ll be able to place cups on real tables using your phone’s camera. When you tap on a surface, a cup will appear where you touched.
- In VR: You’ll use a VR controller to pick up and place cups in a virtual world, like in a game.
Creating a Cup Game Using Unity for AR and VR 2025 – Steps to Run :
1. Setting Up Unity for AR and VR:
For AR (Mobile Devices):
- Open Unity and create a new project (if you haven’t already) named “CupGame”.
- Set Up the AR Environment:
- Go to File > Build Settings and select Android (or iOS if you are using an iPhone).
- For Android, make sure you have Android SDK and JDK installed on your system.
- For iOS, ensure you have Xcode installed.
- Go to File > Build Settings and select Android (or iOS if you are using an iPhone).
- Install AR Foundation:
- Go to Window > Package Manager.
- In the Package Manager, search for AR Foundation and ARCore (for Android) or ARKit (for iOS). Install both.
- Set Up AR Camera:
- In your scene, create an empty GameObject named AR Session.
- Add the AR Session and AR Session Origin components from the AR Foundation package to this object.
- Then, drag the AR Camera from the AR Foundation package into the scene as a child of AR Session Origin.
- Add AR Button:
- Create a UI Button under a Canvas (right-click in Hierarchy > UI > Button).
- Create the script
ARButtonInteraction.cs
for the button (see the previous steps) to handle the cup interaction when the user taps the button.
- Test AR on Your Mobile Device:
- Build and deploy the project to your mobile device.
- For Android: Go to File > Build Settings, click Build and Run. Connect your phone via USB and make sure Developer Mode is enabled.
- For iOS: Build the app and run it through Xcode after connecting the iPhone.
For VR (Headset such as Oculus Rift, HTC Vive):
- Set Up the XR Environment:
- Go to Edit > Project Settings > XR Settings and enable Virtual Reality Supported.
- Choose your VR SDK (Oculus, OpenVR, etc.) depending on your VR headset.
- Create XR Rig:
- Create an empty GameObject called XR Rig (right-click in the Hierarchy > Create Empty).
- Right-click on XR Rig > XR > XR Rig to add the XR camera and controller setup.
- Add XR Interactions:
- Add the XRGrabInteractable component to your cup model (so it can be grabbed with the VR controller).
- Attach the XR Controller components to the VR controllers in your scene.
- Test VR on Your Headset:
- Make sure your VR headset is connected to your PC.
- Hit the Play button in Unity to test the VR version. You should be able to pick up the cup using the VR controllers.
2. Running the Game:
For AR:
- Build the AR Game:
- Go to File > Build Settings, make sure your platform is set to Android or iOS.
- Click Build and Run to deploy the game directly to your phone.
- When you run the app on your phone, the cup should appear and be interactable. Use your phone’s screen to tap and pick up or drop the cup.
For VR:
- Build the VR Game:
- Make sure you’ve set up your VR device (Oculus Rift, HTC Vive, etc.).
- Hit Play in Unity to test the VR game. You’ll be able to use the VR controllers to grab and drop the cup.
3. Additional Notes for Testing:
- For AR:
Make sure you’ve set up your phone to allow AR applications. For Android, enable Developer Mode and make sure ARCore is supported on your device. - For VR:
Ensure the VR headset is connected, and check for compatibility with Unity (e.g., Oculus Integration if you’re using an Oculus headset).
4. Testing the Cup Interaction:
Once you’ve set everything up:
- In AR: When you tap on the screen, the cup will attach to the camera. Tap again to drop it.
- In VR: Use the VR controllers to pick up and drop the cup.
Once these steps are followed, you’ll be able to test the cup game on either an AR mobile app or a VR headset!


Here’s an image showing the output of the Cup Game in both AR and VR, with the cup in a real-world environment (AR) and in a 3D virtual space (VR). It also includes a score counter and timer for added interaction! Let me know if you’d like any changes.
Challenges in the Creating a Cup Game Using Unity for AR and VR 2025
While developing and playing the Cup Game, there are a few challenges that can arise, especially when working with Augmented Reality (AR) and Virtual Reality (VR).
- Device Compatibility (AR)
One of the biggest challenges in AR is ensuring that the game works across different devices. AR relies on the camera and sensors of your phone, so if the phone is not AR-enabled, the game won’t function properly. Not all smartphones support ARCore or ARKit, which are required for AR games. This can limit who can play the game and may need extra testing on different devices. - Tracking and Stability (AR)
In AR, the cup is placed into the real world using the camera, which relies on good lighting and stable surfaces for proper tracking. Sometimes, if the environment is too dark or the surface isn’t stable enough, the cup might appear to float or move unpredictably, which can break the immersion. To fix this, the game needs to be optimized for various environments. - Controller Responsiveness (VR)
In VR, the biggest challenge is ensuring the controllers are responsive and accurately track your hand movements. If the VR setup is not calibrated correctly, it can feel awkward to grab or drop the cup. The player might struggle with interacting smoothly with the cup, which can make the game frustrating instead of fun. Regular testing and adjustments to the VR system are needed to fix this. - Motion Sickness (VR)
VR can cause motion sickness for some people, especially if there is too much movement or if the frame rate is low. If the game’s movement feels unnatural or jerky, it can make players feel dizzy. To avoid this, it’s essential to make sure the game runs smoothly and follows best practices to prevent discomfort. - User Experience (AR & VR)
Both AR and VR games can be tricky to design when it comes to making the controls feel natural. Whether in AR or VR, players should easily understand how to interact with the cup. Complex or unclear controls can make the game feel frustrating rather than fun. Designing intuitive, simple interactions is key to a good user experience.
Conclusion:
Creating a cup game in Unity for both AR and VR gives you hands-on experience with these technologies and teaches you how to integrate 3D objects into real or virtual spaces. The game offers interactive fun, whether you’re in the real world with an AR device or immersed in a virtual world with a VR headset.
Creating a Cup Game Using Unity for AR and VR 2025
For AR-VR Notes | Click Here |
For Big Data Analytics (BDA) Notes | Click Here |