Last active
June 20, 2019 19:55
-
-
Save tsubaki/9302d4870e28b61ca2542af1755d557f to your computer and use it in GitHub Desktop.
AR Foundation create object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.XR.ARFoundation; | |
[RequireComponent(typeof(ARSessionOrigin))] | |
public class SpawnObject : MonoBehaviour { | |
private ARSessionOrigin origin; | |
private List<ARRaycastHit> hitResults = new List<ARRaycastHit>(); | |
[SerializeField] GameObject prefab; | |
private void Awake() | |
{ | |
origin = GetComponent<ARSessionOrigin>(); | |
} | |
void Update () | |
{ | |
if(Input.GetMouseButtonDown(0)){ | |
if( origin.Raycast(Input.GetTouch(0).position, hitResults)) | |
{ | |
Instantiate(prefab, hitResults[0].pose.position, Quaternion.identity); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment