- Home /
This question was
closed May 18, 2018 at 10:04 PM by
hornymiku.
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
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
GUI text not showing in scene or game view 0 Answers
SpriteRender.color not changing the color 1 Answer
Scale fishing rod in one direction 2 Answers