简体   繁体   English

“Collision2D”不包含“GameObject”的定义(使用碰撞器时)

[英]'Collision2D' does not contain a definition for 'GameObject' (while using colliders)

I am using "GameObject" for reference without errors but when I use OnColissionEnter2D using the same GameObject, it gives me an error.我使用“GameObject”作为参考而没有错误,但是当我使用相同的 GameObject 使用 OnColissionEnter2D 时,它给了我一个错误。 I tried changing GameObject to gameObject on the Collision code and it worked but the code inside it doesn't work.我尝试在碰撞代码上将 GameObject 更改为 gameObject 并且它有效但其中的代码不起作用。 I also tried changing the public references to 'gameObjects" but then I got more errors to not change it. WHAT SHOULD I DO NOW??? The Code enter image description here enter image description here我也尝试更改对“gameObjects”的公共引用,但后来我遇到了更多错误,无法更改它。我现在应该做什么???代码在此处输入图像描述 在此处输入图像描述

First things first, I do not recommend coding in Notepad++.首先,我不建议在 Notepad++ 中编码。 Secondly, col.GameObject is not a thing, you are trying to get a Type from the collider.其次, col.GameObject 不是一个东西,你试图从对撞机获取一个类型。 You have to use gameObject otherwise it's never going to work.你必须使用 gameObject 否则它永远不会工作。 Last but not least, you are trying to check if the name of the collided object is Spawner, you are never using the Spawner you referenced at the top of your code.最后但并非最不重要的是,您正在尝试检查碰撞对象的名称是否为 Spawner,您从未使用在代码顶部引用的 Spawner。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GameObject' 不包含 'AddForce' 的定义 || Unity3D - GameObject' does not contain a definition for 'AddForce' || Unity3D 使用Physical2D检测2个对撞机的碰撞 - Detecting collision for 2 colliders using physics2d 使用多个对撞机找到与GameObject发生碰撞的两个对撞机 - Find both colliders involved in a collision on GameObject with Multiple colliders 错误 CS0138:“使用命名空间”指令只能应用于命名空间; '碰撞2D' - error CS0138: A 'using namespace' directive can only be applied to namespaces; 'Collision2D' Unity-将Collider2D转换为Collision2D - Unity - Convert Collider2D to Collision2D 错误 CS1061:“GameObject”不包含“localPosition”的定义 - error CS1061: 'GameObject' does not contain a definition for 'localPosition' GameObject 的快速滑动移动不会与 Colliders 发生碰撞 - Fast swipe movement of GameObject does not collide with Colliders “UnityEngine.GameObject[]”不包含“Transform”错误的定义 - 'UnityEngine.GameObject[]' does not contain a definition for `Transform' error 使用Roslyn时,控制台不包含ReadKey的定义 - Console does not contain a definition for ReadKey while using Roslyn 检测一个游戏对象的多个碰撞器之一是否与另一个游戏对象的另一个碰撞器发生碰撞 - Detect if one of multiple colliders of a GameObject has a collision with another Collider of a different GameObject
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM