Skip to content

Instantly share code, notes, and snippets.

@hackertron
Last active July 8, 2021 15:24
Show Gist options
  • Save hackertron/15d4bd633cc673b160d4a4ca3110f0ac to your computer and use it in GitHub Desktop.
Save hackertron/15d4bd633cc673b160d4a4ca3110f0ac to your computer and use it in GitHub Desktop.
InputHandler
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>();
private bool spawned = false;
private GameObject SpawnedObject;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void SpawnButton()
{
if(spawned)
{
SpawnedObject.SetActive(false);
spawned = false;
}
else
{
SpawnObject(AR_object);
}
}
public void SpawnButton2()
{
if (spawned)
{
SpawnedObject.SetActive(false);
spawned = false;
}
else
{
SpawnObject(AR_object);
}
}
public void SpawnButton3()
{
if (spawned)
{
SpawnedObject.SetActive(false);
spawned = false;
}
else
{
SpawnObject(AR_object);
}
}
public void SpawnObject(GameObject AR_object)
{
Ray ray = AR_Camera.ScreenPointToRay(Input.mousePosition);
if (raycastManager.Raycast(ray, hits))
{
Pose pose = hits[0].pose;
SpawnedObject = Instantiate(AR_object, pose.position, pose.rotation);
spawned = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment