You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class GetCameraDistance : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
private Camera _camera;
|
|
|
|
|
private Vector3 _cameraOrientation;
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
_camera = GetComponent<Camera>();
|
|
|
|
|
_cameraOrientation = Vector3.Normalize(transform.GetChild(0).position - transform.position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float GetDistance(Transform trans)
|
|
|
|
|
{
|
|
|
|
|
float cos = Vector3.Dot(Vector3.Normalize(trans.position - transform.position), _cameraOrientation);
|
|
|
|
|
float distance = (trans.position - transform.position).magnitude * cos;
|
|
|
|
|
return distance;
|
|
|
|
|
}
|
|
|
|
|
}
|