Learn Technologies

Unity Missions slider

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” :

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.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x