Unity Errors

Asked 1 years ago, Updated 1 years ago, 60 views

I started studying "First Unity" on the official Unity website.

using System.Collections;
using System.Collections.General;
using UnityEngine;

public class DangerWall:MonoBehavior {
    // Callback called when in contact with an object 
    void OnCollisionEnter (Collision hit)
    {
        // If the tag of the object you contacted is "Player" 
        if(hit.gameObject.CompareTag("Player")){

            // Get current scene number 
            intsceneIndex=SceneManager.GetActiveScene().buildIndex;

            SceneManager.LoadScene(sceneIndex);
        } 
    }



}

The error only occurs in

int sceneIndex=SceneManager.GetActiveScene().buildIndex; 

SceneManager.LoadScene(sceneIndex);


in the
section of eSceneManager does not exist in this context br
The error appears.
Please tell me where the problem is!

unity3d

2022-09-30 17:04

2 Answers

Obstacle and Restart→The use seems to be insufficient compared to the re-read scene code.
This may be the cause of the error.

using the link

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


2022-09-30 17:04

using UnityEngine.SceneManagement;

is required.


2022-09-30 17:04

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.