I need to do a raycasthit2d on an image but it only works only when I move the camera manually over the image, but I need to do it with the mouse position I have:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class raycast : MonoBehaviour {
public LayerMask layer;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
RaycastHit2D hit =Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition),Vector2.zero);
if(hit.collider != null){
Debug.Log("yaaaa");
}
}
}