Hey! im making a loading screen within Unity and i need to check if a continue button is pressed so the loading can start. Im Checking if the Continue button is pressed with a public void, but I get an error when putting:
if (ContinueButtonPressed)
{
(start loading)
}
when trying that I get the error “Cannot implicitly convert type void to bool”
ideas? here’s my code so far:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class SceneLoader : MonoBehaviour {
private bool loadScene = false;
public Button ContinueButton;
public Text FirstText;
public Text SecondText;
public Text ThirdText;
public Text loadingText;
[SerializeField]
private int scene;
[SerializeField]
private Text LoadingText;
public void ContinueButtonPressed()
{
FirstText.enabled = false;
SecondText.enabled = false;
ThirdText.enabled = false;
}
// Updates once per frame
void Update() {
// If the player has pressed the space bar and a new scene is not loading yet...
if (loadScene == false)
{
if (ContinueButtonPressed())
{
LoadingText.enabled = true;
// ...set the loadScene boolean to true to prevent loading a new scene more than once...
loadScene = true;
// ...change the instruction text to read "Loading..."
loadingText.text = "Loading...";
// ...and start a coroutine that will load the desired scene.
StartCoroutine(LoadNewScene());
}
}
// If the new scene has started loading...
if (loadScene == true) {
// ...then pulse the transparency of the loading text to let the player know that the computer is still working.
loadingText.color = new Color(loadingText.color.r, loadingText.color.g, loadingText.color.b, Mathf.PingPong(Time.time, 1));
}
}
// The coroutine runs on its own at the same time as Update() and takes an integer indicating which scene to load.
IEnumerator LoadNewScene() {
// This line waits for 3 seconds before executing the next line in the coroutine.
// This line is only necessary for this demo. The scenes are so simple that they load too fast to read the "Loading..." text.
yield return new WaitForSeconds(3);
// Start an asynchronous operation to load the scene that was passed to the LoadNewScene coroutine.
AsyncOperation async = Application.LoadLevelAsync(scene);
// While the asynchronous operation to load the new scene is not yet complete, continue waiting until it's done.
while (!async.isDone) {
yield return null;
}
}
}