【问题标题】:Unity c#: making an array of class type equal to FindObjectOfType [closed]Unity c#:使类类型的数组等于 FindObjectOfType [关闭]
【发布时间】:2019-03-22 02:15:10
【问题描述】:

在我正在处理的 c# 脚本中,我有这段代码

 public class Attractor : MonoBehaviour {

 public Rigidbody rb;

 private void FixedUpdate()
 {
     //physics code
     Attractor[] attractors = FindObjectOfType<Attractor>();
 }

我目前收到一条错误消息

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

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

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    你想要 FindObjectsOfType

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-30
      相关资源
      最近更新 更多