I'm trying to make a Instance at the mouse position but it doesn't work
Solution 1:
Input.mousePosition
is in screen pixel space!
You most probably rather want to use Camera.ScreenToWorldSpace
public class attack : MonoBehaviour
{
public Transform prefab;
// you will need to figure this out
public float desiredDistanceInFrontOfCamera;
[SerializeFiel] private Camera _camera;
private void Awake()
{
if(!_camera) _camera = Camera.main;
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector3 mousePos = Input.mousePosition;
mousePos.z = desiredDistanceInFrontOfCamera;
Vector3 spawnPos = _camera.ScreenToWorldPoint(mousePos);
Instantiate(prefab, spawnPos, Quaternion.identity);
}
}
}