'i want to use the build index in an if else statement
im pretty new to C#, im getting an error (10,35): error CS1503: Argument 1: cannot convert from 'bool' to 'string' but i dont know how to fix it. i want change if the cursor is visible or not based on what scnene is active
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Cursorhide : MonoBehaviour
{
void Update()
{
if(SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex < 1))
{
Cursor.visible = true;
}
else
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
}
}
Solution 1:[1]
LoadScene expects a string, like LoadScene("mainMenu")
you put ...index < 1 in it. This evaluates to a boolean: true/false.
Not sure what your goal is, but you can do this:
if(SceneManager.GetActiveScene().buildIndex < 1))
{
Cursor.visible = true;
}
- Maybe the
LoadScenewas auto-completed by accident? Otherwise, please clarify your goal.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KYL3R |
