es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

El tipo o nombre de espacio de nombres ‘SyncListString’ no pudo encontrarse (¿falta una directiva de uso o una referencia de ensamblado?).

Hola, soy principiante y estoy creando un juego multijugador utilizando Mirror siguiendo este video: https://www.youtube.com/watch?v=w0Dzb4axdcw&list=PLDI3FQoanpm1X-HQI-SVkPqJEgcRwtu7M&index=3. En este video ha creado un script de matchmaking y lo he seguido paso a paso, pero no sé por qué estoy obteniendo este error. He revisado el código muchas veces y todo está igual, pero él no obtiene ningún error mientras que yo sí. Por favor, ayuda. Este es mi código y por favor, explíquelo de forma sencilla, soy principiante.

“`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;

namespace MirrorBasics {
[System.Serializable]
public class Match {
public string matchID;
public SyncListGameObject players = new SyncListGameObject ();

<pre><code> public Match(string matchID, GameObject player) {
this.matchID = matchID;
players.Add (player);
}

public Match () { }
}

[System.Serializable]
public class SyncListGameObject : SyncList<gameobject> { }

[System.Serializable]
public class SyncListMatch : SyncList<match> { }

public class MatchMaker : NetworkBehaviour {
public static MatchMaker instance;

public SyncListMatch matches = new SyncListMatch ();
public SyncListString matchIDs = new SyncListString ();

void Start() {
instance = this;
}

public bool HostGame (string _matchID, GameObject _player) {
if (!matchIDs.Contains(_matchID)) {
matchIDs.Add (_matchID) ;
matches.Add (new Match (_matchID, _player));
Debug.Log ("Match generado");
return true;
} else {
Debug.Log ("El ID del match ya existe");
return false;
}
}

public static string GetRandomMatchID () {
string _id = string.Empty;
for (int i = 0; i < 5; i++) {
int random = Random.Range(0, 36);
if (random < 26) {
_id += (char)(random + 65);
} else {
_id += (random – 26).ToString ();
}
}
Debug.Log("ID de Match Aleatorio: "+_id);
return _id;
}
}
</code></pre>

}
“`

Tags:  , , , ,

Answer

  1. Avatar for davy.ai

    El error que estás obteniendo probablemente se debe al uso del símbolo “<” en las definiciones de clase de SyncListGameObject y SyncListMatch.

    En C#, el símbolo “<” se utiliza para especificar el tipo genérico con el que una clase o método está trabajando. Sin embargo, en HTML (que se utiliza para formatear texto en sitios web, incluyendo descripciones de videos de YouTube), el símbolo “<” se convierte a “<” con fines de visualización.

    Para solucionar este error, simplemente reemplaza “<” por “<” en las definiciones de clase de SyncListGameObject y SyncListMatch, de esta manera:

    [System.Serializable]
    public class SyncListGameObject : SyncList<gameobject> { }
    
    [System.Serializable]
    public class SyncListMatch : SyncList<match> { }
    

    Después de hacer estos cambios, el código debería compilar sin errores. ¡Buena suerte con el desarrollo de tu juego multijugador!

Comments are closed.