*
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class CrossHair : MonoBehaviour {
|
||||
public Texture CrosshairTexture;
|
||||
private RaycastHit hit;
|
||||
private bool hasHit;
|
||||
private Vector3 target;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
public Vector3 Target{
|
||||
get{return target; }
|
||||
}
|
||||
|
||||
public bool HasHit{
|
||||
get{return hasHit; }
|
||||
}
|
||||
|
||||
public RaycastHit HitInfo{
|
||||
get{return hit; }
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
var ray = camera.ViewportPointToRay (new Vector3(0.5f,0.5f,0.0f));
|
||||
hasHit = Physics.Raycast (ray, out hit);
|
||||
if (hasHit) {
|
||||
target = hit.point;
|
||||
} else {
|
||||
target = ray.origin + ray.direction.normalized * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnGUI(){
|
||||
Vector2 screenCenter = new Vector2 (Screen.width / 2, Screen.height / 2);
|
||||
|
||||
Graphics.DrawTexture (new Rect(
|
||||
screenCenter.x - (CrosshairTexture.width / 2),
|
||||
screenCenter.y - (CrosshairTexture.height / 2),
|
||||
CrosshairTexture.width,
|
||||
CrosshairTexture.height), CrosshairTexture);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user