Quintus Smit
asked on
Trying to place a an object in AR on a detected plane, using Visual Scripting (Bolt) in Unity
I am trying to convert the script below to a visual script (Bolt) in Unity.
The application uses AR foundation to detect a plane, then place a game object on the plane when you tap the screen.
Here is a video of that (The demonstrations starts at 1:30)
The script works, I am just not that familiar with Visual Scripting.
Here is the script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
[RequireComponent(typeof(ARRaycastManager))]
public class PlaceScript : MonoBehaviour
{
public GameObject portalToPlace;
private GameObject spawnedPOrtal;
ARRaycastManager arRaycastManager;
Vector2 touchPosition;
static List<ARRaycastHit> hits = new List<ARRaycastHit>();
// Start is called before the first frame update
void Start()
{
arRaycastManager = GetComponent<ARRaycastManager>();
}
// Update is called once per frame
void Update()
{
if (!TryGetTouchPosition(out Vector2 touchPosition))
return;
if (arRaycastManager.Raycast(touchPosition, hits, TrackableType.PlaneWithinPolygon))
{
var hitpose = hits[0].pose;
if (spawnedPOrtal == null)
{
spawnedPOrtal = Instantiate(portalToPlace, hitpose.position, hitpose.rotation);
//spawnedPOrtal = Instantiate(portalToPlace, hitpose.position, portalRotation.rotation);
}
}
}
bool TryGetTouchPosition(out Vector2 touchPosition)
{
if (Input.touchCount > 0)
{
touchPosition = Input.GetTouch(0).position;
return true;
}
touchPosition = default;
return false;
}
}
and this is what I have in VS:
You can see in red where the errors are so far, although that may be only the tip of the iceberg.
Here are closeups of the errors:
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.