我有一个列表(名为Within
),其中包含类型为GameObject
的对象。GameObject
是许多其他类的父类,包括Dog
和Ball
。我想编写一个方法,如果Within包含任何类型为Ball
的对象,则返回true,但我不知道该怎么做。
我尝试使用C#中提供的Count<>
,Any<>
,Find<>
等几种方法,但我无法使它们起作用。
public bool DetectBall(List<GameObject> Within)
{
//if Within contains any object of type ball:
{
return true;
}
}