using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class IconTest : MonoBehaviour {

    public Image icon;
    public float distance = 50;
    public LayerMask layer;
    // Use this for initialization
    void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {

        //if mouse button (left hand side) pressed instantiate a raycast
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 pos = Input.mousePosition;
            //pos = Camera.main.ScreenToViewportPoint(Input.mousePosition);
            //pos = Camera.main.ViewportToScreenPoint(Input.mousePosition);

            icon.enabled = true;
            icon.transform.position= pos;
        }
    }

    void Update2()
    {
        //if mouse button (left hand side) pressed instantiate a raycast
        if (Input.GetMouseButtonDown(0))
        {
            //create a ray cast and set it to the mouses cursor position in game
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, distance, layer))
            //if (Physics.Raycast(ray, out hit, distance))
            {
                icon.enabled = true;
                icon.transform.position = hit.point;
            }
        }
    }
}
