Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity c#:使类类型的数组等于FindObjectOfType_C#_Unity3d - Fatal编程技术网

Unity c#:使类类型的数组等于FindObjectOfType

Unity c#:使类类型的数组等于FindObjectOfType,c#,unity3d,C#,Unity3d,在我正在编写的c#脚本中,我有以下代码 public class Attractor : MonoBehaviour { public Rigidbody rb; private void FixedUpdate() { //physics code Attractor[] attractors = FindObjectOfType<Attractor>(); } 公共类吸引子:单行为{ 公共刚体; 私有void FixedUpdate() { /

在我正在编写的c#脚本中,我有以下代码

 public class Attractor : MonoBehaviour {

 public Rigidbody rb;

 private void FixedUpdate()
 {
     //physics code
     Attractor[] attractors = FindObjectOfType<Attractor>();
 }
公共类吸引子:单行为{
公共刚体;
私有void FixedUpdate()
{
//物理代码
吸引子[]吸引子=FindObjectOfType();
}
我目前得到一个错误,说

错误CS0029无法将类型“Attractor”隐式转换为“Attractor[]”


我应该怎么做才能修复此错误

您想要FindObjects的类型

Attractor[] attractors = FindObjectsOfType<Attractor>();
Attractor[]attractors=FindObjectsOfType();

您想要类型的FindObjects

Attractor[] attractors = FindObjectsOfType<Attractor>();
Attractor[]attractors=FindObjectsOfType();