脚本要与放靶心图片的的物体相关联
//靶心图片
public Texture texture;
//射击信息
private string info;
void OnGUI()
{
//计算准心图片的坐标
Rect rect = new Rect(Input.mousePosition.x - (texture.width >>1),Screen.height - Input.mousePosition.y - (texture.height >> 1),texture.width,texture.height);
//绘制准心贴图
GUI.DrawTexture(rect,texture);
//输出射击结果
GUILayout.Label(info + "Position:"+Input.mousePosition);
}
void Update ()
{
//创建从摄像机位置与鼠标位置之间的射线
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
//判断是否打中
if(Physics.Raycast(ray,out hit))
{
info = "YES";
}
else
{
info = "NO";
}
}