Hi everyone, I have created a script that I use to create and add to an array of objects.
The code for the class constructor is as follows;
using UnityEngine;
using System.Collections;
public class Dialogue: MonoBehaviour{
private int _x;
private int _y;
private string _text = "";
public int X {
get { return _x; }
set { _x = value; }
}
public int Y {
get { return _y; }
set { _y = value; }
}
public string Text {
get { return _text; }
set { _text = value; }
}
}
extending this, I have created a function in a separate file which enabled me to create new objects and add them to the array;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ArrayTest: MonoBehaviour {
List<Dialogue> boxList = new ArrayList();
public void DialogueAdd(string text, int width, int height){
Dialogue newDiag = new Dialogue();
newDiag.Dialogue = text;
newDiag.X = width;
newDiag.Y = height;
boxList.Add (newDiag);
}
void Start(){
DialogueAdd ("some text", 22, 42);
DialogueAdd ("some more text", 12, 24);
DialogueAdd ("even more text", 6, 22);
Debug.Log (boxList);
}
}
The problem is, when my script is compiled I get the following error;
Assets/Scripts/Dialogue/ArrayTest.cs(7,49): error CS0029: Cannot implicitly convert type `System.Collections.ArrayList' to `System.Collections.Generic.List<Dialogue>'