PlaceOnPlane.cs 678 B

1234567891011121314151617181920212223242526
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityARInterface;
  5. public class PlaceOnPlane : ARBase
  6. {
  7. [SerializeField]
  8. private Transform m_ObjectToPlace;
  9. void Update ()
  10. {
  11. if (Input.GetMouseButton(0))
  12. {
  13. var camera = GetCamera();
  14. Ray ray = camera.ScreenPointToRay(Input.mousePosition);
  15. int layerMask = 1 << LayerMask.NameToLayer("ARGameObject"); // Planes are in layer ARGameObject
  16. RaycastHit rayHit;
  17. if (Physics.Raycast(ray, out rayHit, float.MaxValue, layerMask))
  18. m_ObjectToPlace.transform.position = rayHit.point;
  19. }
  20. }
  21. }