如何检测 2D 精灵的所有边缘点是否被触摸?

huangapple go评论74阅读模式
英文:

How to detect if all edge points of a 2D sprite are touched?

问题

我正在尝试检测玩家是否触摸了2D精灵的所有边缘点(触摸输入触摸),如果是这样,就增加一个点。该形状是带有多边形碰撞器的2D精灵。

我还在形状的顶部绘制了一条线渲染器,该线与多边形碰撞器的触摸相碰,用作玩家的指示器。

作为一名初学者,我一直在为此而努力。我该如何实现这一目标?任何帮助将不胜感激。

编辑:
遵循willow的方法:

英文:

I am trying to detect if the player has touched (touch input touch) all the edge points of a 2D sprite, and if so, increment a point. The shape is a 2D sprite with a polygon collider.

如何检测 2D 精灵的所有边缘点是否被触摸?

I am also drawing a line renderer on top of the shape where the touch collides with the polygon collider. To serve as an indicator for the player.

如何检测 2D 精灵的所有边缘点是否被触摸?

As a beginner, I have been struggling with this a lot. How can I achieve this? Any help would be greatly appreciated.

Edit:

Following willow's approach:

如何检测 2D 精灵的所有边缘点是否被触摸?

答案1

得分: 1

There is one easy way ( without so much mathematics ) is to add Rigidbody2D/Collider2D around your circles, then you check if the player touch them in order. every small rectangle is a Rigidbody2D/Collider2D, so you raycast, if it hits, add it to an array. when touch finishes, check if all rectangles have been touches in order with a For loop 1,2,3,4,5,6. the more rigidbodies you have, the more accurate you are.

英文:

There is one easy way ( without so much mathematics ) is to add Rigidbody2d/Collider2d around your circles, then you check if the player touch them in order. every small rectangle is a Rigidbody2d/Collider2d, so you raycast , if it hits, add it to an array. when touch finishes, check if all rectangles have been touches in order with a For loop 1,2,3,4,5,6. the more rigidbodies you have, the more accurate you are.

如何检测 2D 精灵的所有边缘点是否被触摸?

huangapple
  • 本文由 发表于 2023年3月15日 21:13:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75745217.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定