创建列表时,出现以下错误:使用泛型型别system.collections.generic.list'需要1'个型别参数
下面是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyPotionForever : MonoBehaviour
{
public static List namesOfDestroyedObjects = new List();
// Start is called before the first frame update
void Start()
{
if(namesOfDestroyedObjects.Count>0){
for (int i = 0; i < namesOfDestroyedObjects.Count; i++) {
Destroy(GameObject.Find(namesOfDestroyedObjects[i]));
}
}
}
void OnTriggerEnter(){
namesOfDestroyedObjects.Add(this.gameObject.name);
Destroy(this.gameObject);
}
// Update is called once per frame
void Update()
{
}
}
2条答案
按热度按时间k10s72fa1#
你需要声明你的列表有哪种类型。例如:
顺便说一句你不需要检查:
在第一次检查for循环时,如果“namesOfDestroyedObjects.Count”不大于0,则for循环将立即中断。
9o685dep2#
在C#中创建列表:
您必须指定
List<>
的类型。如List<int>
或List<Object>
。具体取决于您的需要。