I can not access a class in another script in UNITY 2D

0

Hi, I'm having trouble calling PlayerBase and playerBase in another script

This is the error that gives: Assets / Scripts / MainMenu / SelectScreenManager.cs (112,16): error CS0246: The type or namespace name 'PlayerBase' could not be found. Are you missing an assembly reference?

Script that has class PlayerBase

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

    public class CharacterManager : MonoBehaviour
    {

        public int numberOfUsers;
        public List<PlayerBase>players = new List<PlayerBase>();// Lista com todos os players e tipos de player

        //Uma lista que contem tudo que a gente precisa sobre cada personagem separado,
        //Por agora, contem id e seu correspondende prefab
        public List<CharacterBase> characterList = new List<CharacterBase>();



        //Nos usamos essa funcao pra encontrar os personagens pelo id deles
        public CharacterBase returnCharacterWithID(string id)
        {
            CharacterBase retVal = null;

            for (int i = 0; i < characterList.Count; i++)
            {
                if (string.Equals(characterList[i].charId,id))
                {
                    retVal = characterList[i];
                    break;
                }
            }

            return retVal;
        }

        //Nos usamos esse aqui pra retorna o player pelo personagem criado, states
        public PlayerBase returnPlayerFromStates(StateManager states)
        {
            PlayerBase retVal = null;

            for (int i = 0; i < players.Count; i++)
            {
            if (players[i].playerStates == states)
                {
                    retVal = players[i];
                    break;
                }
            }
            return retVal;
        }

        public static CharacterManager instace;
        public static CharacterManager GetInstance()
        {
            return instace;
        }

        void Awake()
        {
            instace = this;
            DontDestroyOnLoad(this.gameObject);
        }

        [System.Serializable]
        public class CharacterBase
        {
            public string charId;
            public GameObject prefab;
        }

    [System.Serializable]
    public class PlayerBase
    {
        public string playerId;
        public string inputId;
        public PlayerType playerType;
        public bool hasCharacter;
        public GameObject playerPrefab;
        public StateManager playerStates;
        public int score;

        public enum PlayerType
        {
            user,
            ai,
            simulation
        }
    }
}

Script giving error

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




public class SelectScreenManager : MonoBehaviour {

    public int numberOfPlayers = 1;
    public List<PlayerInterfaces> plInterfaces = new List<PlayerInterfaces>();
    public PotraitInfo[] potraitPrefabs;//Todas as entradas do potrait
    public int maxX;//Quantos potraits a gente no X e no Y
    public int maxY;
    PotraitInfo[,] charGrid;//A grid que faz pra selecao entre eles


    public GameObject potraitCanvas;// As canvas que conte todos os potrait


    bool loadLevel; //Se esta carregando o level
    public bool bothPlayersSelected;

    CharacterManager charManager;


    #region Singleton
    public static SelectScreenManager instace;
    public static SelectScreenManager GetInstance()
    {
        return instace;
    }
    void Awake()
    {
        instace = this;
    }
    #endregion



	void Start () {

        //Inicia pegando as referencias do character manager
        charManager = CharacterManager.GetInstance();
        numberOfPlayers = charManager.numberOfUsers;


        //E criamos o grid
        charGrid = new PotraitInfo[maxX, maxY];

        int x = 0;
        int y = 0;


        potraitPrefabs = potraitCanvas.GetComponentsInChildren<PotraitInfo>();

        //Assim pegamos todos os potraits
        for (int i = 0; i < potraitPrefabs.Length; i++ )
        {
            //E assim pegamos o grid position de cada potrait
            potraitPrefabs[i].posX += x;
            potraitPrefabs[i].posY += y;

            charGrid[x, y] = potraitPrefabs[i];

            if(x < maxX -1)
            {
                x++;
            }
            else{
                x = 0;
                y++;
            }
        }
	}
	private void Update()
	{
        if(!loadLevel)
        {
            for (int i = 0; i < plInterfaces.Count; i++)
            {
                if(i<numberOfPlayers)
                {
                    if(!charManager.players[i].hasCharacter)
                    {
                        plInterfaces[i].playerBase = charManager.players[i];

                     }
                }
            }

        }
	}
	[System.Serializable]
    public class PlayerInterfaces
    {
        public PotraitInfo activePotrait;// A corrent que ativa potrait pro player 1
        public PotraitInfo previewPotrait;
        public GameObject selector;//Que seleciona o indicador do player 1
        public Transform charVisPos;//Vizualiza a posicao do player 1
        public GameObject createdCharacter;// Cria o personagem do player 1

        public int activeX;//Ativa o X e o Y pro player 1
        public int activeY;

        //Algumas variaveis pro alguns inputs
        public bool hitInputOnce;
        public float timerToReset;

        public PlayerBase playerBase;
    }
}
    
asked by anonymous 15.08.2018 / 00:58

1 answer

0

Guilherme, good morning,

I had several similar issues resolved with deleting the precompile and post compilation files in the project folder and close the IDE. So you force it to re-create the assembly list and can fix the problem.

Good luck

    
13.09.2018 / 17:13