This question was 
             closed Jun 16, 2018 at 04:46 PM by 
             Veilbrides. 
            
 
             
               Question by 
               Veilbrides · Jun 16, 2018 at 03:08 PM · 
                c#unity 5instantiateinstance  
              
 
              Problem with Instantiate custom class
Hello. Im trying to make a prototype of Dungeon Dice Monster, just to learn how this art of game would work. I want to add 15 dices in a List but everytime when I call Dice newDice = new Dice(); it is always null, but I can't find the error. Hope you can help me out Here is the code
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 
 public class Game : MonoBehaviour {
     Board gameboard;
     List<Dice> Player1Dice; // List of Dice Pool PLAYER 1
     List<Dice> Player2Dice; // List of Dice Pool PLAYER 2 
                             // Use this for initialization
 
 
     void Start() {
         Player1Dice = new List<Dice>(); // create new List
         Player2Dice = new List<Dice>(); // create new List
         createDicePool(); // Method to fill 15 Dices into List<> 
     }
 
     void createDicePool()
     {
         for (int i = 1; i <= 15; i++)
         {
             Dice _newDice = new Dice(); // create new Dice
 
             if (_newDice == null) // check if newDice is Null
                 print("Meh");
             Player1Dice.Add(_newDice);
 
             print("Added");
         }
         //checkLists(Player1Dice);
     }
 }
 
               Dice class using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Dice : MonoBehaviour{
List<Symbol> _Sides; Color _DiceColor; //Symbols the Rarity of the Dice // Use this for initialization void Start() { _Sides = new List<Symbol>(6); Symbol newSym; for (int i = 1; i <= 6; i++) { int id = Random.Range(1, 6); // print("ID was: " + id); newSym = new Symbol(); // print(newSym.getDescription()); _Sides.Add(newSym); } for (int j = 1; j <= _Sides.Count; j++) { Debug.Log(_Sides[j].getSymbolName() + "\n"); } } public Dice getDice() { return this; } }
               Comment
              
 
               
              Follow this Question
Related Questions
Why is object reference not set to an instance? 1 Answer
Instantiate is not working in unity 5.6.4f1 0 Answers
How do i Instantiate sub-Points with in Multiple Points?? 0 Answers
TreeInstance is not working properly 1 Answer
how do i remember a just instantiated prefab as a variable gameobject? 1 Answer