#I Need help with Level Select (Turtorial)

1 messages · Page 1 of 1 (latest)

lost veldt
spice shoal
#

What

#

Have you tried Google yet

lost veldt
#

No

#

wait

lost veldt
#

i dont have time today to google

lost veldt
#

Hey i made a gui and i need to do so it locks and unlockes the levels

#

@spice shoal sorry for ping ^^^^^

spice shoal
#

Then do that lel

#

I've no idea how your GUI works so I literally cannot help

#

In terms of how you could implement it

lost veldt
#

i made a normal button and a swiping panel

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class PageSwiper : MonoBehaviour, IDragHandler, IEndDragHandler
{
    private Vector3 panelLocation;
    public float percentThreshold = 0.2f;
    public float easing = 0.5f;
    public int totalPages = 1;
    private int currentPage = 1;

    // Start is called before the first frame update
    void Start()
    {
        panelLocation = transform.position;
    }
    public void OnDrag(PointerEventData data)
    {
        float difference = data.pressPosition.x - data.position.x;
        transform.position = panelLocation - new Vector3(difference, 0, 0);
    }
    public void OnEndDrag(PointerEventData data)
    {
        float percentage = (data.pressPosition.x - data.position.x) / Screen.width;
        if (Mathf.Abs(percentage) >= percentThreshold)
        {
            Vector3 newLocation = panelLocation;
            if (percentage > 0 && currentPage < totalPages)
            {
                currentPage++;
                newLocation += new Vector3(-Screen.width, 0, 0);
            }
            else if (percentage < 0 && currentPage > 1)
            {
                currentPage--;
                newLocation += new Vector3(Screen.width, 0, 0);
            }
            StartCoroutine(SmoothMove(transform.position, newLocation, easing));
            panelLocation = newLocation;
        }
        else
        {
            StartCoroutine(SmoothMove(transform.position, panelLocation, easing));
        }
    }
    IEnumerator SmoothMove(Vector3 startpos, Vector3 endpos, float seconds)
    {
        float t = 0f;
        while (t <= 1.0)
        {
            t += Time.deltaTime / seconds;
            transform.position = Vector3.Lerp(startpos, endpos, Mathf.SmoothStep(0f, 1f, t));
            yield return null;
        }
    }
}

PageSwiper.cs

spice shoal
#

That's cool and all but I still don't really know how you want to switch scenes

#

I mean with a button it could be this:

#
private bool unlocked;
private void OnEnable() => button.onClick.AddListener(SwitchScene)

private void SwitchScene()
{
    if(unlocked)
       SceneManager.LoadScene("Scene");
}
lost veldt
spice shoal
#
private const int levels;
private bool[] unlocked = new bool[levels]
spice shoal
#

That's an array

lost veldt
spice shoal
#

so if(levelcomplete) unlocked [0] = true

lost veldt
spice shoal
#

if(secondlevelcomplete) unlocked [1] = true

#

It's an array

lost veldt
#

ok

lost veldt
#

How do i use it to level select?

spice shoal
#

Depends how your system works

#

Also I was sleeping, therefore I wasn't responding