Skip to content

Instantly share code, notes, and snippets.

@n1ckfg
Created November 1, 2016 14:45
Show Gist options
  • Select an option

  • Save n1ckfg/15ddbdb9b3a2136b62eb8e29e54bcdcc to your computer and use it in GitHub Desktop.

Select an option

Save n1ckfg/15ddbdb9b3a2136b62eb8e29e54bcdcc to your computer and use it in GitHub Desktop.
Random screen position Unity
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