Помогите заменить устаревший метод OnLevelWasLoaded()

Форум для самых маленьких, а так же тех, кому недосуг читать справку самостоятельно.

Помогите заменить устаревший метод OnLevelWasLoaded()

Сообщение shtein 25 сен 2022, 16:15

Всем привет. Начинаю изучать программирование и наткнулся в курсе по Unity, с проблемой устаревшего метода. Как заменить, так что бы работал скрипт, не понимаю. Помогите пожалуйста.

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

public class GameManager : MonoBehaviour
{
public static GameManager instance;
private GameObject[] puzzlePieces;
private Sprite[] puzzleImages;
private PuzzlePiece[,] Matrix = new PuzzlePiece[GameVariables.MaxRows, GameVariables.MaxColums];
private Vector3 screenPositionToAnimate;
private PuzzlePiece PieceToAnimate;
private int toAnimateRow, toAnimateColumn;
private float animSpeed = 10f;
private int puzzleIndex;
private GameState gameState;

void Awake()
{
MakeSingleton();
}

void Start()
{
puzzleIndex = -1;
}

[System.Obsolete]
void OnLevelWasLoaded()
{

if (Application.loadedLevelName == "Gameplay")
{
if (puzzleIndex > 0)
{
LoadPuzzle();
GameStarted();
}
}
}

void GameStarted()
{
int index = Random.Range(0, GameVariables.MaxSize);
puzzlePieces[index].SetActive(false);
for (int row = 0; row < GameVariables.MaxRows; row++)
{
for (int column = 0; column < GameVariables.MaxColums; column++)
{
if (puzzlePieces[row * GameVariables.MaxColums + column].activeInHierarchy)
{
Vector3 point = GetScreenCoordinatesFromViewPort(row, column);
puzzlePieces[row * GameVariables.MaxColums + column].transform.position = point;
Matrix[row, column] = new PuzzlePiece();
Matrix[row, column].GameObject = puzzlePieces[row * GameVariables.MaxColums + column];
Matrix[row, column].OriginalRow = row;
Matrix[row, column].OriginalColumn = column;
}
else
{
Matrix[row, column] = null;
}
}
}
}

private Vector3 GetScreenCoordinatesFromViewPort(int row, int column)
{
Vector3 point = Camera.main.ViewportToWorldPoint(new Vector3(0.255f * row, 1 - 0.235f * column, 0));
point.z = 0;
return point;
}
void LoadPuzzle()
{
puzzleImages = Resources.LoadAll<Sprite>("Sprites/BG " + puzzleIndex);
puzzlePieces = GameObject.Find("Puzzle Holder").GetComponent<PuzzleHolder>().puzzlePiece;
for (int i = 0; i < puzzlePieces.Length; i++)
{
puzzlePieces[i].GetComponent<SpriteRenderer>().sprite = puzzleImages[i];
}
}

void MakeSingleton()
{
if (instance == null)
{
Destroy(gameObject);
}
else
{
instance = this;
DontDestroyOnLoad(gameObject);
}
}

public void SetPuzzleIndex(int puzzleIndex)
{
this.puzzleIndex = puzzleIndex;
}
}
shtein
UNец
 
Сообщения: 1
Зарегистрирован: 25 сен 2022, 16:05

Вернуться в Почемучка

Кто сейчас на конференции

Сейчас этот форум просматривают: Yandex [Bot] и гости: 32