Created
April 15, 2017 03:06
-
-
Save twobob/9bb9c28aad96e6106236f669e562a1c4 to your computer and use it in GitHub Desktop.
Demonstration of a screen-centered reticle in 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 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