Question by
batuhanboran32 · Feb 17, 2021 at 03:50 PM ·
imagescrollviewscrollbarscroll viewcontent
Scroll view script wont show button images
Hi all of you I am making mobile game and when I was working in UI I had issue this scroll view -> content have 3 button images and texts like this but when I start it game doesnt show the images
using UnityEngine;
using UnityEngine.UI;
public class swipe_menu : MonoBehaviour
{
public GameObject scrollbar;
private float scroll_pos = 0;
float[] pos;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
pos = new float[transform.childCount];
float distance = 1f / (pos.Length - 1f);
for (int i = 0; i < pos.Length; i++)
{
pos[i] = distance * i;
}
if (Input.GetMouseButton(0))
{
scroll_pos = scrollbar.GetComponent<Scrollbar>().value;
}
else
{
for (int i = 0; i < pos.Length; i++)
{
if (scroll_pos < pos[i] + (distance / 2) && scroll_pos > pos[i] - (distance / 2))
{
scrollbar.GetComponent<Scrollbar>().value = Mathf.Lerp(scrollbar.GetComponent<Scrollbar>().value, pos[i], 0.1f);
}
}
}
for (int i = 0; i < pos.Length; i++)
{
if (scroll_pos < pos[i] + (distance / 2) && scroll_pos > pos[i] - (distance / 2))
{
Debug.LogWarning("Current Selected Level" + i);
transform.GetChild(i).localScale = Vector2.Lerp(transform.GetChild(i).localScale, new Vector2(1.2f, 1.2f), 0.1f);
for (int j = 0; j < pos.Length; j++)
{
if (j != i)
{
transform.GetChild(j).localScale = Vector2.Lerp(transform.GetChild(j).localScale, new Vector2(0.8f, 0.8f), 0.1f);
}
}
}
}
}
}
This is code I am using on content for interactable swift. Code works fine other projects but somehow I can see images like this
screenshot-3.png
(27.9 kB)
screenshot-4.png
(15.0 kB)
Comment