I am trying to build a small app for learning how AR Foundation and Unity works. Pretty new on this. I am able to place the object on plane detected in a scene. Just not sure how to get hold of the camera and then adjust the scale of the object by y-axis which will scale the object vertically or even a line renderer kinda just how it works in iOS measure app after placing points on the plane detected. If someone could guide me on this, it would be helpful. Thank you.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
[RequireComponent(typeof(ARRaycastManager))]
public class ARTapObjectSpawn : MonoBehaviour
{
public GameObject gameObjectToInst;
private GameObject spawnedObj;
private ARRaycastManager _arRaycastManager;
private Vector2 touchPosition;
static List<ARRaycastHit> hits = new List<ARRaycastHit>();
private void Awake()
{
_arRaycastManager = GetComponent<ARRaycastManager>();
}
bool TryGetTouchPosition(out Vector2 touchPosition){
if(Input.touchCount > 0){
touchPosition = Input.GetTouch(0).position;
return true;
}
touchPosition = default;
return false;
}
// 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(spawnedObj == null){
spawnedObj = Instantiate(gameObjectToInst, hitPose.position, hitPose.rotation);
}
else{
spawnedObj.transform.position = hitPose.position;
}
}
}
}