Как сделать границы скролинга

Сделал скролинг по одному гайду и столкнулся с проблемой. Иконки не исчезают когда я делаю скролл а просто идут дальше по экрану. Как мне сделать чтобы иконки пропадали, когда они выходят за желтую рамку? введите сюда описание изображения

Скрипт скролинга

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Snapcontroll : MonoBehaviour
{
[Range(1, 50)]
[Header("Controllers")]
public int panCount;
[Range(0, 500)]
public int panOffset;
[Range(0f, 20f)]
public float snapSpeed;
[Range(0f, 5f)]
public float scaleOffset;
[Range(1f, 20f)]
public float scaleSpeed;
[Header("Other objects")]
public GameObject panPrefab;
public ScrollRect ScrollRect;

private GameObject[] instPans;
private Vector2[] pansPos;
private Vector2[] pansScale;
private Vector2 contentvector;

private RectTransform contentRect;
private int selectedPanID;
private bool isScrolling;


// Start is called before the first frame update
private void Start()
{
    contentRect = GetComponent<RectTransform>();
    instPans = new GameObject[panCount];
    pansPos = new Vector2[panCount];
    pansScale = new Vector2[panCount];
    for (int i = 0; i < panCount; i++)
    {
        instPans[i] = Instantiate(panPrefab.GetComponent<Transform>().GetChild(i).gameObject, transform, false);
        if (i == 0) continue;
          instPans[i].transform.localPosition = new Vector2(instPans[i-1].transform.localPosition.x + panPrefab.GetComponent<RectTransform>().sizeDelta.x + panOffset,
          instPans[i].transform.localPosition.y);
          pansPos[i] = -instPans[i].transform.localPosition;


    }
}
private void FixedUpdate()
{
    if (contentRect.anchoredPosition.x >= pansPos[0].x && !isScrolling|| contentRect.anchoredPosition.x <= pansPos[pansPos.Length -1].x)
    {
        ScrollRect.inertia = false;
    }
    float nearesPos = float.MaxValue;
    for (int i =0; i < panCount; i++)
    {
        float distance = Mathf.Abs(contentRect.anchoredPosition.x - pansPos[i].x);
        if (distance < nearesPos)
        {
            nearesPos = distance;
            selectedPanID = i;
        }
        float scale = Mathf.Clamp(1 / (distance / panOffset) * scaleOffset, 0.5f, 1f);
        pansScale[i].x = Mathf.SmoothStep(instPans[i].transform.localScale.x, scale + 0.3f, scaleSpeed * Time.fixedDeltaTime);
        pansScale[i].y = Mathf.SmoothStep(instPans[i].transform.localScale.y, scale + 0.3f, scaleSpeed * Time.fixedDeltaTime);
        instPans[i].transform.localScale = pansScale[i];
    }
    float scrollVelocity = Mathf.Abs(ScrollRect.velocity.x);
    if (scrollVelocity < 400 && !isScrolling) ScrollRect.inertia = false;
    if (isScrolling || scrollVelocity > 400) return;
    contentvector.x = Mathf.SmoothStep(contentRect.anchoredPosition.x, pansPos[selectedPanID].x, snapSpeed * Time.fixedDeltaTime);
    contentRect.anchoredPosition = contentvector;
}
public void Scrolling(bool scroll)
{
    isScrolling = scroll;
    if (scroll) ScrollRect.inertia = true;
}
}

Ответы (0 шт):