gpt4 book ai didi

c# - 找不到类型或命名空间名称

转载 作者:太空宇宙 更新时间:2023-11-03 23:37:21 25 4
gpt4 key购买 nike

我有一个用 C# 编写的代码,我在 unity5 中使用它,但是因为是针对旧版本的 unity 我有一个小问题。

error CS0246: The type or namespace name `collider' could not be found. Are you missing a using directive or an assembly reference?

代码是

Vector3 worldPosition = GetComponent<collider>().bounds.center + Vector3.up * collider.bounds.size.y * 0.5f;

如果你想要代码的透视here .

最佳答案

错误告诉您解决方案中没有名为 collider 的类型或命名空间。

我从您的 PasteBin 解决方案中注意到您正在使用 typeof(Collider)。因此我认为类型是 Collider 而不是 collider

您可能还需要此对象的实例才能使用属性:

Collider collider = GetComponent<Collider>();

然后您可以使用 collider 对象来访问属性大小和中心。

关于c# - 找不到类型或命名空间名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30175562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com