Files
CityOfTheDead.Unity/Assets/Scripts/CrossHair.cs
T
2025-05-13 05:12:44 +03:00

50 lines
1.0 KiB
C#

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 = GetComponent<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);
}
}