Hello, I am a beginner for programmer, and I have a question I am trying to use Scroll Rect to develop a loop menu, and I want to make it as the picture to the menu, how should I do?? I have tried to use transform.localScale to change the Button size, but there is a "depth" problem which I don't know how to slove it?
Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using DG; public class ScrollRectSnap4 : MonoBehaviour { public RectTransform panel; public Button[] bttn; public RectTransform center; public float[] distance; public float[] distReposition; private bool dragging = false; public int bttnDistance; private int minButtonNum; private int bttnLenght; public float minDistance; void Start () { bttnLenght = bttn.Length; distance = new float[bttnLenght]; distReposition = new float[bttnLenght]; bttnDistance = (int)Mathf.Abs(bttn[1].GetComponent<RectTransform>().anchoredPosition.x - bttn[0].GetComponent<RectTransform>().anchoredPosition.x); } void Update () { for (int i = 0; i < bttn.Length; i++) { distReposition[i] = center.transform.position.x - bttn[i].transform.position.x; distance [i] = Mathf.Abs (distReposition[i]); if (distReposition [i] > 1200) { float curX = bttn [i].GetComponent<RectTransform> ().anchoredPosition.x; float curY = bttn [i].GetComponent<RectTransform> ().anchoredPosition.y; Vector2 newAnchoredPos1 = new Vector2 (curX + (bttnLenght * bttnDistance), curY); //Debug.Log (bttn[i].name + "newAnchoredPos1: " + newAnchoredPos1); bttn [i].GetComponent<RectTransform> ().anchoredPosition = newAnchoredPos1; } if (distReposition [i] < -1200) { float curX = bttn [i].GetComponent<RectTransform> ().anchoredPosition.x; float curY = bttn [i].GetComponent<RectTransform> ().anchoredPosition.y; Vector2 newAnchoredPos2 = new Vector2 (curX - (bttnLenght * bttnDistance), curY); bttn [i].GetComponent<RectTransform> ().anchoredPosition = newAnchoredPos2; } } minDistance = Mathf.Min (distance); for (int a = 0; a < bttn.Length; a++) { if (minDistance == distance [a]) { minButtonNum = a; bttn[a].transform.localScale = Vector3.Lerp(bttn[a].transform.localScale,new Vector3(1f,1f,1f),Time.deltaTime*5); } else { bttn[a].transform.localScale = Vector3.Lerp(bttn[a].transform.localScale,new Vector3(0.7f,0.7f,0.7f),Time.deltaTime*5); } } if (!dragging) { //LerpToBttn (minButtonNum * -bttnDistance); LerpToBttn (-bttn[minButtonNum].GetComponent<RectTransform>().anchoredPosition.x); } } void LerpToBttn (float position){ //Debug.Log ("Position: " + -bttn[minButtonNum].GetComponent<RectTransform>().anchoredPosition.x); float newX = Mathf.Lerp (panel.anchoredPosition.x, position, Time.deltaTime * 5f); Vector2 newPosition = new Vector2 (newX, panel.anchoredPosition.y); panel.anchoredPosition = newPosition; } public void StartDrag(){ dragging = true; } public void EndDrag(){ dragging = false; } } This is the process of my menu, I have tried to make the center Image bigger than others, but I don't know how to change the farest object look smaller