- Home /
How can I implement Camera.ScreenToWorldPoint(); in 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, and how i can make that. ( I understand that i need to use it in the position = part. but it not works, and the documentation and explanations that I found in the internet, are very difficult to understand for me, because English isn't my first language ) Thank you.
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