Closed Tengpaz closed 2 months ago
图片所示两状态下组件Notify
均为Not Enable
状态
我很抱歉,不过这个问题的描述以及代码看起来实在让人困惑,如果您只是需要一个指引箭头,您应当只是书写一个类来直接控制Arrow
是否为Active
。
如果您的需求仅仅是让箭头初始时不会Active
,你可以在控制显示的类中加入判断玩家是否有离开过碰撞箱,如果玩家从未离开碰撞箱,就不要让自己显示。或者在初始状态下不要让玩家和碰撞箱重叠。
并且我建议您重构一下自己的代码,现在的显示逻辑有些过于紧耦且复杂。
很抱歉我不能完全解决您的问题。如果您需要更多帮助,可以单独联系我。
对于简单的碰撞箱重叠检测,您可以使用如下代码的方法:
void CheckBoundsOverlap(Collider otherCollider)
{
Collider myCollider = GetComponent<Collider>();
if (myCollider.bounds.Intersects(otherCollider.bounds))
{
// Do something...
Debug.Log("Bounds overlap with " + otherCollider.gameObject.name);
}
}
感谢学长提供的代码!碰撞箱重叠目前还不会所以处理比较复杂www还有问题我单独找学长您,谢谢助教!!
Unity游戏对象显示Bug
环境工具
问题阐述
如图
GameObject EndBed
子物体DownArrow
初始未运行时为禁用状态同时子物体
Bed
中的代码End
和Notify Script Component
均初始时为禁用状态运行预期效果为角色接触床
EndBed
物体后上方不会显示提示箭头DownArrow
实际运行图片
物体接触
EndBed
物体时此时
Hierarchy
栏内DownArrow
物体变为Active
状态物体离开
EndBed
物体时此时
Hierarchy
栏内DownArrow
物体变为Not Active
即禁用状态补充信息
图示物体
DownArrow
物体的Inspector
栏信息此为代码
Notify
代码内容此为代码
End
的代码内容解决需求
使得无论角色是否触碰物体
EndBed
,上方箭头初始时都不会Active