- Home /
Random movement of crosshair inside ui box
I want to make a crosshair move randomly inside a ui box. At every move it should generate a Random vector only inside the bounding box and then the crosshair should move to that position
Comment
Answer by SoshJam · Mar 30, 2019 at 05:36 PM
Use this: (replace the 5's with your box's dimensions.)
float newX = Random.Range(-5,5);
float newY = Random.Range(-5,5);
transform.position = new Vector2(newX,newY);
Your answer
![](https://koobas.hobune.stream/wayback/20220612194551im_/https://answers.unity.com/themes/thub/images/avi.jpg)