Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Assets/Scripts/MainMenu/SelectScreenManager.cs(112,16): error CS0246: The type or namespace name `Pl

Discussion in '2D' started by guilhermeprata, Aug 15, 2018.

  1. guilhermeprata

    guilhermeprata

    Joined:
    Jul 22, 2018
    Posts:
    9
    I have o problema my script SelectScreenBase I can't reference my class PlayerBase I don't know why

    This is PlayerBase script
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5.     public class CharacterManager : MonoBehaviour
    6.     {
    7.  
    8.         public int numberOfUsers;
    9.         public List<PlayerBase>players = new List<PlayerBase>();// Lista com todos os players e tipos de player
    10.  
    11.         //Uma lista que contem tudo que a gente precisa sobre cada personagem separado,
    12.         //Por agora, contem id e seu correspondende prefab
    13.         public List<CharacterBase> characterList = new List<CharacterBase>();
    14.  
    15.  
    16.  
    17.         //Nos usamos essa funcao pra encontrar os personagens pelo id deles
    18.         public CharacterBase returnCharacterWithID(string id)
    19.         {
    20.             CharacterBase retVal = null;
    21.  
    22.             for (int i = 0; i < characterList.Count; i++)
    23.             {
    24.                 if (string.Equals(characterList[i].charId,id))
    25.                 {
    26.                     retVal = characterList[i];
    27.                     break;
    28.                 }
    29.             }
    30.  
    31.             return retVal;
    32.         }
    33.  
    34.         //Nos usamos esse aqui pra retorna o player pelo personagem criado, states
    35.         public PlayerBase returnPlayerFromStates(StateManager states)
    36.         {
    37.             PlayerBase retVal = null;
    38.  
    39.             for (int i = 0; i < players.Count; i++)
    40.             {
    41.             if (players[i].playerStates == states)
    42.                 {
    43.                     retVal = players[i];
    44.                     break;
    45.                 }
    46.             }
    47.             return retVal;
    48.         }
    49.  
    50.         public static CharacterManager instace;
    51.         public static CharacterManager GetInstance()
    52.         {
    53.             return instace;
    54.         }
    55.  
    56.         void Awake()
    57.         {
    58.             instace = this;
    59.             DontDestroyOnLoad(this.gameObject);
    60.         }
    61.  
    62.         [System.Serializable]
    63.         public class CharacterBase
    64.         {
    65.             public string charId;
    66.             public GameObject prefab;
    67.         }
    68.  
    69.     [System.Serializable]
    70.     public class PlayerBase
    71.     {
    72.         public string playerId;
    73.         public string inputId;
    74.         public PlayerType playerType;
    75.         public bool hasCharacter;
    76.         public GameObject playerPrefab;
    77.         public StateManager playerStates;
    78.         public int score;
    79.  
    80.         public enum PlayerType
    81.         {
    82.             user,
    83.             ai,
    84.             simulation
    85.         }
    86.     }
    87. }
    This is SelectScreenManager
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine.SceneManagement;
    6.  
    7.  
    8.  
    9.  
    10. public class SelectScreenManager : MonoBehaviour {
    11.  
    12.     public int numberOfPlayers = 1;
    13.     public List<PlayerInterfaces> plInterfaces = new List<PlayerInterfaces>();
    14.     public PotraitInfo[] potraitPrefabs;//Todas as entradas do potrait
    15.     public int maxX;//Quantos potraits a gente no X e no Y
    16.     public int maxY;
    17.     PotraitInfo[,] charGrid;//A grid que faz pra selecao entre eles
    18.  
    19.  
    20.     public GameObject potraitCanvas;// As canvas que conte todos os potrait
    21.  
    22.  
    23.     bool loadLevel; //Se esta carregando o level
    24.     public bool bothPlayersSelected;
    25.  
    26.     CharacterManager charManager;
    27.  
    28.  
    29.     #region Singleton
    30.     public static SelectScreenManager instace;
    31.     public static SelectScreenManager GetInstance()
    32.     {
    33.         return instace;
    34.     }
    35.     void Awake()
    36.     {
    37.         instace = this;
    38.     }
    39.     #endregion
    40.  
    41.  
    42.  
    43.     void Start () {
    44.  
    45.         //Inicia pegando as referencias do character manager
    46.         charManager = CharacterManager.GetInstance();
    47.         numberOfPlayers = charManager.numberOfUsers;
    48.  
    49.  
    50.         //E criamos o grid
    51.         charGrid = new PotraitInfo[maxX, maxY];
    52.  
    53.         int x = 0;
    54.         int y = 0;
    55.  
    56.  
    57.         potraitPrefabs = potraitCanvas.GetComponentsInChildren<PotraitInfo>();
    58.  
    59.         //Assim pegamos todos os potraits
    60.         for (int i = 0; i < potraitPrefabs.Length; i++ )
    61.         {
    62.             //E assim pegamos o grid position de cada potrait
    63.             potraitPrefabs[i].posX += x;
    64.             potraitPrefabs[i].posY += y;
    65.  
    66.             charGrid[x, y] = potraitPrefabs[i];
    67.  
    68.             if(x < maxX -1)
    69.             {
    70.                 x++;
    71.             }
    72.             else{
    73.                 x = 0;
    74.                 y++;
    75.             }
    76.         }
    77.     }
    78.     private void Update()
    79.     {
    80.         if(!loadLevel)
    81.         {
    82.             for (int i = 0; i < plInterfaces.Count; i++)
    83.             {
    84.                 if(i<numberOfPlayers)
    85.                 {
    86.                     if(!charManager.players[i].hasCharacter)
    87.                     {
    88.                         plInterfaces[i].playerBase = charManager.players[i];
    89.  
    90.                      }
    91.                 }
    92.             }
    93.  
    94.         }
    95.     }
    96.     [System.Serializable]
    97.     public class PlayerInterfaces
    98.     {
    99.         public PotraitInfo activePotrait;// A corrent que ativa potrait pro player 1
    100.         public PotraitInfo previewPotrait;
    101.         public GameObject selector;//Que seleciona o indicador do player 1
    102.         public Transform charVisPos;//Vizualiza a posicao do player 1
    103.         public GameObject createdCharacter;// Cria o personagem do player 1
    104.  
    105.         public int activeX;//Ativa o X e o Y pro player 1
    106.         public int activeY;
    107.  
    108.         //Algumas variaveis pro alguns inputs
    109.         public bool hitInputOnce;
    110.         public float timerToReset;
    111.  
    112.         public PlayerBase playerBase;
    113.     }
    114. }
     
  2. netramz

    netramz

    Joined:
    May 22, 2018
    Posts:
    16
    So if you can't reference something then that must mean that it does not currently exist within the context. Since the PlayerBase playerBase within the PlayerInterfaces class is a public data member, are you sure that there is something being assigned to it?

    I did not read through the code very in-depth, but perhaps you just need to initialize the PlayerBase with the statement 'PlayerBase playerBase = new PlayerBase();' or you are forgetting to assign it elsewhere in your code or in the editor.
     
  3. guilhermeprata

    guilhermeprata

    Joined:
    Jul 22, 2018
    Posts:
    9
    Só my I can assign my class CharacterBase but playerbase no, my code it like the same of tutorial
     
  4. netramz

    netramz

    Joined:
    May 22, 2018
    Posts:
    16
    How is the CharacterBase assigned vs the PlayerBase? Are they linked in the editor or are they explicitly declared in your scripts?

    Perhaps linking to the tutorial you are following will allow others to assist you better.
     
  5. guilhermeprata

    guilhermeprata

    Joined:
    Jul 22, 2018
    Posts:
    9
    Hey so I fix put public CharacterManager.PlayerBase playerbase in the script I want reference, thanks for everything