Skip to content

Instantly share code, notes, and snippets.

@twobob
Created April 15, 2017 03:06
Show Gist options
  • Save twobob/9bb9c28aad96e6106236f669e562a1c4 to your computer and use it in GitHub Desktop.
Save twobob/9bb9c28aad96e6106236f669e562a1c4 to your computer and use it in GitHub Desktop.
Demonstration of a screen-centered reticle in Unity
using UnityEngine;
using System.Collections;
public class Reticle : MonoBehaviour
{
public Texture2D reticle;
void Awake ()
{
// Set up reticle
GameObject go = new GameObject ("Reticle");
go.transform.position = new Vector3 (0.5f, 0.5f, 0);
go.transform.localScale = new Vector3(0, 0, 1);
GUITexture tex = go.AddComponent<GUITexture> ();
tex.texture = reticle;
Rect ins = new Rect (-(reticle.width / 2), -(reticle.height / 2), reticle.width, reticle.height);
tex.pixelInset = ins;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment