[*] Pixel Perfect: [Да] < /li>
Камера рендеринга: Основная камера < /li>
Плость Расстояние: 100 < /li>
Сортировка слоя: по умолчанию < /li>
Порядок: 0 < /li>
< /ul>
. Settings
- UI Scale Mode: Constant Pixel Size
- Scale Factor: 1
- Reference Pixels Per Unit: 100
[Header("Check For Overlap")]
public RectTransform PlayerBar;
public RectTransform LeftBar;
public Rect RectOne;
public Rect RectTwo;
public bool overlapping;
//Check if the two canvas element Rects overlap each other
public void CheckForOverlap()
{
overlapping = false;
// Convert Canvas RectTransforms to World Rects
RectOne = GetWorldRect(LeftBar);
RectTwo = GetWorldRect(PlayerBar);
if (RectOne.Overlaps(RectTwo))
{
overlapping = true;
}
}
public Rect GetWorldRect(RectTransform rt)
{
// Get World corners, take top left
Vector3[] corners = new Vector3[4];
rt.GetWorldCorners(corners);
Vector3 topLeft = corners[0];
// Rect Size ... I'm not sure if this is working correctly?
Vector2 size = new Vector2(rt.rect.size.x, rt.rect.size.y);
return new Rect(topLeft, size);
}
< /code>
Что происходит < /strong> < /p>
'перекрытие' bool мгновенно изменяется на True. < /p>
Прямо возвращается как (пример) < /p>
x -7.5, y 2.5
w 98.5.5, w 98. 164.1667
Подробнее здесь: https://stackoverflow.com/questions/420 ... verlapping
Мобильная версия