How to, with a button, switch to another level when all items are collected?
Hi everyone ! Hope you're doing great. Here's my problem : kinda like everyone I teach myself Unity basic stuff by modifying the Roll-A-Ball tutorial. What I want to do is to change the scene by letting the player click on a button that needs to appear after he collected all of the items. So I made de UI button that works with this script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneSwitch : MonoBehaviour {
public void ScenceSwitcher()
{
SceneManager.LoadScene(2);
}
}
The button works just fine however it shows up before collecting the items. So how am I supposed to code a "when score reaches X items the button shows up" kind of code? Hope you can help me on that.
Thanks a lot!
Answer by exzizt · Mar 27, 2018 at 03:00 AM
Every time your player collects a point, increment a variable. Only allow the button to work if their points collected == the total points in the level variable.
public void ScenceSwitcher()
{
if (Player.PointsCollected == Level.TotalPoints)
{
SceneManager.LoadScene(2);
}
}
Well, thank you for your reply. I've tried it but I got a "unexpected symbol "end-of-file". :/
Your answer
Follow this Question
Related Questions
Button Displacement 0 Answers
On collision enter next scene 2 Answers
Use a string to call a class 2 Answers