using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class PlaceItem : MonoBehaviour
{
#region PRIVATE VARIABLES
// Reference to canvas graphic raycaster
private GraphicRaycaster graphicRaycaster;
// Reference to pointer event data
private PointerEventData pointerEventData;
// Reference to event system in scene
private EventSystem eventSystem;
// Reference to map
private GameObject map;
#endregion
#region MONOBEHAVIOUR CALLBACKS
private void Start()
{
// Find the Raycaster from the GameObject (the Canvas)
graphicRaycaster = FindObjectOfType<GraphicRaycaster>();
// Find the Event System from the Scene
eventSystem = FindObjectOfType<EventSystem>();
// Find the map game object in the scene
map = GameObject.Find("Map");
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
PlaceItemOnMap();
}
}
#endregion
#region PLACE ITEM ON MAP
private void PlaceItemOnMap()
{
// Set up the new Pointer Event
pointerEventData
= new PointerEventData
(eventSystem
);
// Set the Pointer Event Position to that of the mouse position
pointerEventData.position = Input.mousePosition;
// Create a list of Raycast Results
List
<RaycastResult
> results
= new List
<RaycastResult
>();
// Raycast using the Graphics Raycaster and mouse click position
graphicRaycaster.Raycast(pointerEventData, results);
foreach (RaycastResult result in results)
{
Debug.Log(results[0].gameObject);
}
// For every result returned, output the name of the GameObject on the Canvas hit by the Ray (except for the item on mouse pointer)
for (int i = 0; i < results.Count; i++)
{
// Check if number of results hit by the Ray is more than 0
if (results.Count > 0)
{
Debug.Log(i + " : " + results[i].gameObject);
}
}
}
#endregion
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}