Created
November 1, 2016 14:45
-
-
Save n1ckfg/15ddbdb9b3a2136b62eb8e29e54bcdcc to your computer and use it in GitHub Desktop.
Random screen position Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| public class RandomScreenPos : MonoBehaviour { | |
| void Update() { | |
| float x = Random.Range(0f, Screen.width); | |
| float y = Random.Range(0f, Screen.height); | |
| float z = Random.Range(Camera.main.nearClipPlane, Camera.main.farClipPlane); | |
| transform.position = Camera.main.ScreenToWorldPoint(new Vector3(x, y, z)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment