【问题标题】:I have tried to fix this code but I don't know how to我已尝试修复此代码,但我不知道如何
【发布时间】:2022-08-17 00:02:48
【问题描述】:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Collidable : MonoBehaviour
{
    public ContactFilter2D filter;
    private BoxCollider2D boxCollider;
    private Collider2D[] hits = new Collider2D[10];

    protected virtual void Start()
    {
        boxCollider = GetComponent<BoxCollider2D>();
    }

    protected virtual void update()
    {
        // Collision work
        boxCollider.OverlapCollider(filter, hits);
        for (int i = 0; i < hits.length; i++)
        {
            if (hits[i] == null)
                continue;

            Debug.Log(hits[i].name);

            // The array is not cleaned up, so we do it ourself
            hits[i] = null;
        }
    }
}

错误说: 错误 CS1061: \'Collider2D[]\' 不包含 \'length\' 的定义,并且没有可访问的扩展方法 \'length\' 接受类型为 \'Collider2D[]\' 的第一个参数可能是找到(您是否缺少 using 指令或程序集引用?) 我是编码新手。请帮我。

    标签: c# unity3d


    【解决方案1】:

    确保使用大写“L”。 c#中的方法区分大小写 请参阅 Array.Length 方法 https://docs.microsoft.com/en-us/dotnet/api/system.array.length?view=net-6.0

    【讨论】:

      猜你喜欢
      • 2017-01-11
      • 2020-10-16
      • 1970-01-01
      • 2016-04-24
      • 2020-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-03
      相关资源
      最近更新 更多