'SceneManager' does not contain a definition for 'GetActiveScene'
У меня есть следующий код, для управления персонажем. Но при запуске программы выходит ошибка SceneManager does not contain a definition for 'GetActiveScene. Как я понял данная ошибка говорит о том, что у SceneManager нет метода GetActiveScene. Но я не однократно встречал данный код для реализации перезагрузки сцены.
В интернете я не нашёл решение данной проблемы.
Версия Unity - 2020.3.11f1
Весь код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour
{
[SerializeField] private Transform feetPos;
[SerializeField] private LayerMask whatIsGround;
private Rigidbody2D _rigidbody;
private Animator _anim;
private float checkRadius = 0.3f;
private float normalSpeed = 3f;
private float speed = 0;
private float jumpForce = 7f;
private bool facingRight = true;
private bool isGround = true;
private void Start()
{
_rigidbody = GetComponent<Rigidbody2D>();
_anim = GetComponent<Animator>();
}
private void FixedUpdate()
{
isGround = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround);
_rigidbody.velocity = new Vector2(speed, _rigidbody.velocity.y);
if (transform.position.y < 0)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
public void RunLeft()
{
_anim.SetBool("isWalk", true);
if (facingRight)
{
transform.localScale = new Vector3(transform.localScale.x * -1, transform.localScale.y, transform.localScale.z);
facingRight = false;
}
if (speed >= 0f)
speed = -normalSpeed;
}
public void RunRight()
{
_anim.SetBool("isWalk", true);
if (!facingRight)
{
transform.localScale = new Vector3(transform.localScale.x * -1, transform.localScale.y, transform.localScale.z);
facingRight = true;
}
if (speed <= 0f)
speed = normalSpeed;
}
public void OnButtonUp()
{
speed = 0f;
_anim.SetBool("isWalk", false);
}
public void Jump()
{
if (isGround)
{
_anim.SetTrigger("Jump");
_rigidbody.velocity = Vector2.up * jumpForce;
}
}
}
Часть кода в которой ошибка:
if (transform.position.y < 0)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
Ответы (1 шт):
Автор решения: Алексей Шиманский
→ Ссылка
Уверен, что где-то в коде у вас есть собственный скрипт, который называется SceneManager с одноимённым классом. Вот он-то и мешается, потому что идёт конфликт имён