#I Need help with Level Select (Turtorial)
1 messages · Page 1 of 1 (latest)
i dont have time today to google
Hey i made a gui and i need to do so it locks and unlockes the levels
@spice shoal sorry for ping ^^^^^
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
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
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");
}
yes but i have like MORE levels than 1 and have to do so i could enable the bool if i complete a level
private const int levels;
private bool[] unlocked = new bool[levels]
what does this do?
That's an array
array?
so if(levelcomplete) unlocked [0] = true
ok
ok
How do i use it to level select?