using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.XR.ARFoundation; public class Object_Control : MonoBehaviour { [SerializeField] private PlacementObject[] placedObjects; [SerializeField] private Camera arCamera; [SerializeField] private GameObject gameObject; private Vector2 touchPosition = default; private ARRaycastManager aRRaycastManager; private bool is_Hold = false; [SerializeField] private float maxDistanceOnSelection = 25.0f; static List hits = new List(); void Update() { // do not capture events unless the welcome panel is hidden if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { Ray ray = Camera.main.ScreenPointToRay(touch.position); RaycastHit hitObj; ; if(Physics.Raycast(ray,out hitObj, maxDistanceOnSelection)) { if (hitObj.transform.name.Contains("PlaceObject")) { is_Hold = true; } } } if(touch.phase == TouchPhase.Moved) { touchPosition = touch.position; } if(touch.phase == TouchPhase.Ended) { is_Hold = false; } } if (is_Hold) { if (aRRaycastManager.Raycast(touchPosition, hits, UnityEngine.XR.ARSubsystems.TrackableType.All)) { Pose hitPose = hits[0].pose; gameObject.transform.position = hitPose.position; gameObject.transform.rotation = hitPose.rotation; } } } }