Skip to content

Instantly share code, notes, and snippets.

@hackertron
Last active September 28, 2020 11:01
Show Gist options
  • Save hackertron/e9360c8ff61b5bdcccc87f47f8da8d8d to your computer and use it in GitHub Desktop.
Save hackertron/e9360c8ff61b5bdcccc87f47f8da8d8d to your computer and use it in GitHub Desktop.
InputController script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
public class InputManager : MonoBehaviour
{
public GameObject AR_object;
public Camera AR_Camera;
public ARRaycastManager raycastManager;
public List<ARRaycastHit> hits = new List<ARRaycastHit>();
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0))
{
Ray ray = AR_Camera.ScreenPointToRay(Input.mousePosition);
if(raycastManager.Raycast(ray, hits))
{
Pose pose = hits[0].pose;
Instantiate(AR_object, pose.position, pose.rotation);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment