using UnityEngine;
using System.Collections;
public class Cannon : MonoBehaviour {
public float rotSpeed;
Vector3 pointCursor;
void Start () {
}
void Update () {
transform.rotation = Quaternion.Slerp(transform.rotation, Camera.main.transform.rotation, Time.deltaTime*rotSpeed);
RaycastHit hit;
if(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit))
{
Debug.DrawLine(transform.position, hit.point,Color.red);
// Получаем Vector3 hit-а d в который попали
pointCursor = Camera.main.WorldToScreenPoint(hit.point);
}
}
void OnGUI()
{
Rect labelRect = new Rect();
labelRect.x = pointCursor.x-32;
labelRect.y = Screen.height-pointCursor.y-32;
labelRect.width = 64;
labelRect.height = 64;
GUI.Box(labelRect, "");
}
}