简体   繁体   English

如何在 Unity c# 中的另一个游戏对象上使用 OnCollisionStay?

[英]How to use OnCollisionStay on another gameObject in Unity c#?

This is my first stack overflow question, but I'm doing a game jam, and I need to use the OnCollisionStay() void thing on the collider of another game object.这是我的第一个堆栈溢出问题,但我正在做一个游戏卡,我需要在另一个游戏 object 的对撞机上使用 OnCollisionStay() void 东西。 I have tried我努力了

public void TeleportDisplayCircle.OnCollisionStay(Collision2D tpPlatform)

but that didnt work.但这没有用。 Do have any tips to help?有什么提示可以帮助吗? Thanks!谢谢!

You cannot do public void TeleportDisplayCircle.OnCollisionStay(Collision2D tpPlatform)你不能做public void TeleportDisplayCircle.OnCollisionStay(Collision2D tpPlatform)

you have to public void OnCollisionStay(Collision2D tpPlatform) and this method has to be put into the script on some object you want to detect collision stay on您必须public void OnCollisionStay(Collision2D tpPlatform)并且必须将此方法放入您想要检测碰撞停留在某些 object 的脚本中

For next time, what you could do is on the object with the collider, create a script with your code in the void OnCollisionStay() then have this script reference your main script.下一次,您可以在 object 上使用碰撞器,在void OnCollisionStay()中使用您的代码创建一个脚本,然后让该脚本引用您的主脚本。 Then you can create your own void on the main script public void OnCollisionStaying(){} .然后您可以在主脚本public void OnCollisionStaying(){}上创建自己的 void。 Then in your OnCollisionStay() on the collider you can say mainscript.OnCollisionStaying();然后在对撞机上的OnCollisionStay()中,您可以说mainscript.OnCollisionStaying();

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

相关问题 Unity C#GameObject与另一个GameObject发生冲突 - Unity C# GameObject collides with another GameObject Unity 5.6-C#-使用AddComponent将游戏对象添加到另一个游戏对象<T> - Unity 5.6 - C# - Adding a GameObject to another GameObject with AddComponent<T> unity/c#:来自另一个游戏对象的数据 - unity/c#: data from another gameobject 一次OnCollisionStay在C#中统一检测两个平面的碰撞? - OnCollisionStay at a time Collision detection for two plane in C# unity? 如何在统一 c# 中获取 GameObject 的孩子? - How to get children of an GameObject in unity c#? Unity C#从同一GameObject上的另一个脚本获取变量 - Unity C# getting a variable from another script on the same GameObject 尝试将 GameObject 分配给另一个脚本中的变量(Unity C#) - Trying to assign GameObject to variable in another script (Unity C#) 如何在 Unity3d 中将 C# 组件从一个游戏对象传递到另一个游戏对象 - how can I pass a C# component from one gameobject to another in Unity3d Unity、C#、2D:如何将 UI 画布项目(按钮)位置设置为与另一个游戏对象相同的位置? - Unity, C#, 2D : how to set a UI canvas item(button) position to the same position as another gameobject? 如何在 c# function 中使用 2D GameObject 数组作为参数(2D 统一游戏) - How to use 2D GameObject array as a parameter in a c# function ( 2D unity game)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM