In this video you will learn how to make missions slider panels.
Tutorial resources link.
Panel Slider
In order to make panel slider, we will use a free asset package called “iTween“.
Let’s add now the Slider class that’s will manage the movement to the right an left of missions panels. This class contains essentially 2 methods “SlideToLeft” and “SlideToRight” :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | using UnityEngine; public class Slider : MonoBehaviour { public GameObject ContainerPanel; public GameObject[] MissionsPanel; int currentIndex = 0; float containerPrositionX; void Start () { containerPrositionX = ContainerPanel.transform.position.x; } public void SlideToLeft() { if (currentIndex > 0) { currentIndex--; var targetPanel = MissionsPanel[currentIndex]; float targetPositionX = containerPrositionX - targetPanel.transform.position.x; var targetPosition = new Vector3(ContainerPanel.transform.position.x + targetPositionX, ContainerPanel.transform.position.y, ContainerPanel.transform.position.z); iTween.MoveTo(ContainerPanel, targetPosition, 0.5f); } } public void SlideToRight() { if (currentIndex < MissionsPanel.Length - 1) { currentIndex++; var targetPanel = MissionsPanel[currentIndex]; float targetPositionX = containerPrositionX - targetPanel.transform.position.x; var targetPosition = new Vector3(ContainerPanel.transform.position.x + targetPositionX, ContainerPanel.transform.position.y, ContainerPanel.transform.position.z); iTween.MoveTo(ContainerPanel, targetPosition, 0.5f); } } } |
Follow Me For Updates
Subscribe to my YouTube channel or follow me on Twitter or GitHub to be notified when I post new content.