I cannot access a class in another UNITY 2D script

Asked

Viewed 424 times

0

Hi having trouble calling Playerbase and playerBase in another script

This is the mistake 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 Playerbase class

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 that gives 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;
    }
}

1 answer

0

William, good morning,

I had several similar issues resolved with deleting the pre-build and post-build files in the project folder and closing the IDE. So you force him to recreate the Assembly list and can fix the problem.

Good luck

Browser other questions tagged

You are not signed in. Login or sign up in order to post.