Error CS0161 (32,24) and Error CS0103 (37,12)

when i was programming i got these two Error, and i dont know how to fix it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class NewBehaviourScript : MonoBehaviour
{
public GameObject player;
public float TimeBeforeNextScene;
public bool PlayerIsAtTheDoor;
private BoxCollider2D coll;

// Start is called before the first frame update
void Start()
{
coll = GetComponent();
}

// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.E) && PlayerIsAtTheDoor == true)
{
StartCoroutine(_OpenDoor());
}
}

public IEnumerator _OpenDoor()
{
SceneManager.LoadScene(“Scene 2”);
}

private void OnTriggerEnter2D(Collider2D coll)
{
if(collision.gameObject.tag ==“player”)
{
PlayerIsAtTheDoor = true;
}
}

private void OnTriggerExit2D(Collider2D coll)
{
PlayerIsAtTheDoor = false;
}
}

You can fix your own typing mistakes. Here’s how:

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

1 Like

i still dont know how to fix Error CS0161 (32,24). It says not all code paths return a value.

this line

public IEnumerator _OpenDoor()
{
SceneManager.LoadScene(“Scene 2”);
}

You will want to familiarise yourself with how to actually write coroutines: https://docs.unity3d.com/Manual/Coroutines.html

There are examples of how to properly load scenes in the documentation too: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html

i want to go like from the one scene to the other when i interact with like an door

Then read the links I shared and they will show you how to do so.

1 Like