12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class ObjectSelector : MonoBehaviour
- {
- private GameObject currentlySelectedObject;
- public Button deleteButton;
- public Camera arCamera;
- void Update()
- {
- if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
- {
- Ray ray;
- if (arCamera != null)
- ray = arCamera.ScreenPointToRay(Input.GetTouch(0).position);
- else
- ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit))
- {
-
- Debug.Log("Hit " + hit.collider.gameObject.name);
- if (hit.collider.gameObject == gameObject)
- {
- currentlySelectedObject = gameObject;
- deleteButton.gameObject.SetActive(true);
- deleteButton.onClick.AddListener(() => DeleteSelectedObject());
- }
- }
- }
- }
- void DeleteSelectedObject()
- {
- if (currentlySelectedObject != null)
- {
- Debug.Log("Deleting object: " + currentlySelectedObject.name);
-
- Destroy(currentlySelectedObject);
- currentlySelectedObject = null;
- deleteButton.gameObject.SetActive(false);
- deleteButton.onClick.RemoveListener(DeleteSelectedObject);
- this.gameObject.GetComponent<ObjectDropper>().DeleteObject();
- }
- }
- }
|