- Home /
How can i implement Camera.ScreenToWorldPoint(); for the crosshair script?
Hello, i have a problem with my crosshair script, i want to implement Camera.ScreenToWorldPoint(); in it, so my crosshair will be able only to move where the camera is. But i can't figure out how it works.
The code: public Transform anchor; public float maxMoveRadius; public float sensitivity = 1f;
Vector3 position = Vector2.zero;
void Start () {
}
void Update () {
Vector3 moveDelta = new Vector3(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), 0);
position = Vector3.ClampMagnitude(position + moveDelta * sensitivity, maxMoveRadius);
transform.position = anchor.position + position;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612162949im_/https://answers.unity.com/themes/thub/images/avi.jpg)