So, I'm trying to make code that spawns an asteroid at a random position outside the viewport. I created a random number function that returns values between -1 and 2, cutting out values between -0.2 and 1.2. this is then converted to a world position using ScreenToWorldPoint. I've confirmed that the initial screen positions are the expected values, however, after being converted to world points, they strangely always land in the bottom left corner of the screen. stranger still is that its not the exact same position every time, it has slight variation of about 0.2 in both the x and y positions. The following is the code that's supposed to spawn the asteroids:
Vector2 screenPoint = new Vector3(RandomOutsideFloat(), RandomOutsideFloat());
Debug.Log(screenPoint);
Vector3 asteroidPos = Camera.main.ScreenToWorldPoint(screenPoint);
Debug.Log(asteroidPos);
asteroidPos.z = 0;
GameObject asteroid = Instantiate(asteroidPrefab[Random.Range(0, asteroidPrefab.Length)], asteroidPos , Quaternion.identity);