Скрытый текст:
Скрипт который использую сейчас:
Синтаксис:
Используется csharp
using UnityEngine;
public class Marker : MonoBehaviour {
public Transform target;
public RectTransform marker;
public RectTransform arrow;
Vector3 _t;
public Vector2 _d;
public Vector2 _b;
public float _w;
public float _h;
public float soot;
Quaternion arrowZero;
public bool X;
public bool Y;
void Start () {
arrowZero = arrow.rotation;
}
void LateUpdate () {
_t = transform.InverseTransformVector (target.position - transform.position);
if (!Mathf.Approximately(_t.z, 0)) {
_w = Screen.width / 2;
_h = Screen.height / 2;
_w -= 50;
_h -= 50;
_d.x = _t.x;
_d.y = _t.y;
_d /= Mathf.Abs (_t.z);
_d.x = _d.x * soot;
_d.y = _d.y * soot + 50;
_b.x = Mathf.Clamp (_d.x, - _w, _w);
_b.y = Mathf.Clamp (_d.y, - _h, _h);
}
marker.anchoredPosition = _b;
X = !Mathf.Approximately (_d.x, _b.x);
Y = !Mathf.Approximately (_d.y, _b.y);
if (X || Y) {
arrow.rotation = Quaternion.LookRotation (Vector3.forward, - _d);
} else {
arrow.rotation = arrowZero;
}
}
}
public class Marker : MonoBehaviour {
public Transform target;
public RectTransform marker;
public RectTransform arrow;
Vector3 _t;
public Vector2 _d;
public Vector2 _b;
public float _w;
public float _h;
public float soot;
Quaternion arrowZero;
public bool X;
public bool Y;
void Start () {
arrowZero = arrow.rotation;
}
void LateUpdate () {
_t = transform.InverseTransformVector (target.position - transform.position);
if (!Mathf.Approximately(_t.z, 0)) {
_w = Screen.width / 2;
_h = Screen.height / 2;
_w -= 50;
_h -= 50;
_d.x = _t.x;
_d.y = _t.y;
_d /= Mathf.Abs (_t.z);
_d.x = _d.x * soot;
_d.y = _d.y * soot + 50;
_b.x = Mathf.Clamp (_d.x, - _w, _w);
_b.y = Mathf.Clamp (_d.y, - _h, _h);
}
marker.anchoredPosition = _b;
X = !Mathf.Approximately (_d.x, _b.x);
Y = !Mathf.Approximately (_d.y, _b.y);
if (X || Y) {
arrow.rotation = Quaternion.LookRotation (Vector3.forward, - _d);
} else {
arrow.rotation = arrowZero;
}
}
}
А теперь проблемы моей реализации:
1)Если развернуться на 180, то маркер будет показывать в пустоту(эта проблема как в 1ой версии скрипта, так и во 2ой).
Скрытый текст:
2)В скрипте для UI, есть некое значение soot(возможно ругательная аббревиатура, я уже не помню), методом научного тыка было получено значение 666 для разрешения экрана 1024x768. Но при этом в оригинальном скрипте такого не было, при реставрации такого результата не удалось достичь, там так же 666.
Скрытый текст:
Скрытый текст:
Реставрация скрипта:
Синтаксис:
Используется csharp
using UnityEngine;
public class Marker3D : MonoBehaviour {
public Transform target;
public Transform marker;
Vector3 _t;
public Vector3 _d;
public Vector3 _b;
public float _w;
public float _h;
void LateUpdate () {
_t = transform.InverseTransformVector (target.position - transform.position);
if (!Mathf.Approximately(_t.z, 0)) {
_w = Screen.width / 2;
_h = Screen.height / 2;
_w -= 50;
_h -= 50;
_w /= 666;
_h /= 666;
_d.x = _t.x;
_d.y = _t.y;
_d.z = 1;
_d /= Mathf.Abs (_t.z);
_d.x = _d.x;
_d.y = _d.y + 0.075f;
_b.x = Mathf.Clamp (_d.x, - _w, _w);
_b.y = Mathf.Clamp (_d.y, - _h, _h);
_b.z = 1;
}
marker.localPosition = _b;
}
}
public class Marker3D : MonoBehaviour {
public Transform target;
public Transform marker;
Vector3 _t;
public Vector3 _d;
public Vector3 _b;
public float _w;
public float _h;
void LateUpdate () {
_t = transform.InverseTransformVector (target.position - transform.position);
if (!Mathf.Approximately(_t.z, 0)) {
_w = Screen.width / 2;
_h = Screen.height / 2;
_w -= 50;
_h -= 50;
_w /= 666;
_h /= 666;
_d.x = _t.x;
_d.y = _t.y;
_d.z = 1;
_d /= Mathf.Abs (_t.z);
_d.x = _d.x;
_d.y = _d.y + 0.075f;
_b.x = Mathf.Clamp (_d.x, - _w, _w);
_b.y = Mathf.Clamp (_d.y, - _h, _h);
_b.z = 1;
}
marker.localPosition = _b;
}
}
Если кто знает как гуглить или другие решение(а лучше и то и то), дайте знать.