[英]When at least one projectile out of a group hits the target, how to call a function only once per group?
When a shotgun fires a group of pellets, and let's say 1 or 20 pellets hit the target: how do I call a function only once per accurate shot, instead of once per pellet collision?当霰弹枪发射一组弹丸时,假设有 1 或 20 颗弹丸击中目标:如何每次准确射击只调用一次函数,而不是每次弹丸碰撞调用一次?
When using OnCollisionEnter on the projectile or on the target itself, the method gets called for each individual pellet collision.当对射弹或目标本身使用 OnCollisionEnter 时,该方法会为每个单独的弹丸碰撞调用。
Should I use an event for this problem?我应该为这个问题使用一个事件吗? How would I do this?
我该怎么做?
Edit: Ah, I forgot to edit this once I figured it out.编辑:啊,一旦我想通了,我就忘记编辑了。 I think some people might've misunderstood my problem.
我想有些人可能误解了我的问题。
Inside OnCollisionEnter
find ContactPoint.points
.在
OnCollisionEnter
找到ContactPoint.points
。
Now you can use your accuracy calculation here and find out which one is perfect.现在您可以在此处使用您的准确度计算并找出哪一个是完美的。
If perfect, then call function else not.如果完美,则调用函数 else not。
If anyone ever stumbles upon this, the way I've done it is by generating a unique ID for each shot of a weapon, and assigning it to each projectile inside that shot.如果有人偶然发现这一点,我的做法是为武器的每次射击生成一个唯一的 ID,并将其分配给该射击中的每个射弹。 Then any projectile that hits the target will check if that unique ID has called the method yet or not.
然后任何击中目标的射弹都会检查该唯一 ID 是否已调用该方法。 So this way when you fire 1 shot which has 20 projectiles, each projectile that hit the target will do damage to the target, but only knock it back once, no matter how many projectiles hit.
所以这样当你发射 1 发有 20 个射弹的子弹时,每个射中目标的射弹都会对目标造成伤害,但无论击中多少射弹都只会将其击退一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.