Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Temas recientes

Ayuda (este código me da error)

Iniciado por XedZ, Enero 10, 2019, 05:14:16 PM

Tema anterior - Siguiente tema
Enero 10, 2019, 05:14:16 PM Ultima modificación: Enero 20, 2019, 03:56:44 PM por pioj
Como lo soluciono?
 
 
 



   
      Parameter name: index
      System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
      System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
      System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
      Daño.Update () (at Assets/Daño.cs:51)
   

[/quote]
 
 
 
 
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Daño : MonoBehaviour
{
    public Text dañoText;
    public Text velText;
    public Text fueText;
    public Text nameText;
    public Text Crit1Text;
    public Text Crit2Text;
    public Text EntText;
    public Text RotText;
    public Text PreText;
    public Text descText;
    public Text espText;
    public Espada Sword;
    public int selected;
   
    public List<Espada> swordDatabase = new List<Espada>(5);
    // Start is called before the first frame update
    void Start()
    {
        List<Espada> swordDatabase = GameObject.Find("Manager").GetComponent<WeaponManager>().Espadas;
    }
    // Update is called once per frame
    void Update()
    {
        dañoText.text = Sword.Daño.ToString ();
        velText.text = Sword.Vel.ToString();
        fueText.text = Sword.Fue.ToString();
        nameText.text = Sword.Nombre;
        descText.text = Sword.Desc;
        Crit1Text.text = Sword.CRIT1;
        Crit2Text.text = Sword.CRIT2;
        EntText.text = Sword.Entereza.ToString();
        RotText.text = Sword.Rotura.ToString();
        PreText.text = Sword.Presencia.ToString();
        espText.text = Sword.Esp;
 
        Sword = swordDatabase[selected];
    }
}

 
 

cual es la linea 51??
 
Fijate que en start estás redefiniendo una lista:
 
 List<Espada> swordDatabase = GameObject.Find("Manager").GetComponent<WeaponManager>().Espadas;
 
ponelo así:
 

public class Daño : MonoBehaviour
{
    public Text dañoText;
    public Text velText;
    public Text fueText;
    public Text nameText;
    public Text Crit1Text;
    public Text Crit2Text;
    public Text EntText;
    public Text RotText;
    public Text PreText;
    public Text descText;
    public Text espText;
    public Espada Sword;
    public int selected;
   
    public List<Espada> swordDatabase = new List<Espada>(5);
     
   //Para asegurarte
    void Start()
    {
      GameObject manager = GameObject.Find("Manager");
      if(manager == null){
         Debug.Log("No hay manager!");
         Destroy(this);
      }
     
      WeaponManager weaponM = manager.GetComponent<WeaponManager>();
      if(weaponM == null){
         Debug.Log("No hay weapon manager!");
         Destroy(this);
      }
     
       
      swordDatabase = weaponM.Espadas;
    }
   
     
    void Update()
    {
        dañoText.text = Sword.Daño.ToString ();
        velText.text = Sword.Vel.ToString();
        fueText.text = Sword.Fue.ToString();
        nameText.text = Sword.Nombre;
        descText.text = Sword.Desc;
        Crit1Text.text = Sword.CRIT1;
        Crit2Text.text = Sword.CRIT2;
        EntText.text = Sword.Entereza.ToString();
        RotText.text = Sword.Rotura.ToString();
        PreText.text = Sword.Presencia.ToString();
        espText.text = Sword.Esp;
   
        Sword = swordDatabase[selected];
 
 
    }

 
chequea que la lista tenga las cantidades necesarias para que selected tenga sentido, que selected no sea por ej 5 y tengas 2 elementos porque te va a dar un nullreference exception.
 
saludos
 
 

    

Hola , siento responder tan tarde , la linea 51 es:
 

Sword = swordDatabase[selected];

 
Gracias de antemano.

Etiquetas: