任务:
①创建类数组。
②利用Debug输出数组。
③利用Text组件输出。
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DogArray : MonoBehaviour {
class Dog
{
public int old { get; set; }
public string name { get; set; }
//ToString
public override string ToString()
{
return string.Format("old={0} name={1}", old, name);
}
public static implicit operator string(Dog v)
{
throw new NotImplementedException();
}
}
public Text text;
void Start () {
text = GetComponent<Text>();
var dogList = new List<Dog>()
{
new Dog(){old=3,name="狗蛋"},
new Dog(){old=2,name="二狗"},
new Dog(){old=1,name="艾米"},
new Dog(){old=4,name="小白"},
};
foreach(var temp in dogList)
{
Debug.Log(temp);
text.text +=temp.name;
}
}
}