public static void PerformCollision(FightEntity entity, Entity other) { if (entity == null || other == null) { return; } Bullet bullet = other as Bullet; if (bullet != null) { ImpactData entityImpactData = entity.GetImpactData(); ImpactData bulletImpactData = bullet.GetImpactData(); if (GetRelation(entityImpactData.Camp, bulletImpactData.Camp) == RelationType.Friendly) { return; } entity.ApplyDamage(bulletImpactData.Attack); if (bullet.SubEffectTimes()) { GameEntry.Entity.HideEntity(bullet.Id); } return; } }
/// <summary> /// 射线逻辑 /// </summary> /// <param name="elapseSeconds"></param> /// <param name="realElapseSeconds"></param> private void RayEffectUpdate(float elapseSeconds, float realElapseSeconds) { if (isStop) { if (Time.time >= hideTime) { GameEntry.Entity.HideEntity(parentEntityId); } return; } // shootRay是碰撞射线,用于碰撞检测。1000是随便设的,让碰撞检测的射线足够长 if (Physics.Raycast(shootRay, out shootHit, 1000)) { FightEntity entity = shootHit.collider.GetComponent <FightEntity>(); if (entity != null) { entity.ApplyDamage(bulletData.Attack); } else { isStop = true; hideTime = Time.time + 0.1f; return; } // 因为线的长度很长(上面乘以了100),碰撞的时候需要将线最后一个坐标重新设置成碰撞点所在坐标 int preIndex = lineRenderer.positionCount - 1; lineRenderer.SetPosition(preIndex, shootHit.point); // 达到最大效果次数,停止折射 if (lineRenderer.positionCount > bulletEffectData.EffectTimes) { isStop = true; hideTime = Time.time + 0.1f; return; } // 根据线的方向向量和法线,得到反射向量 Vector3 reflectVector = Vector3.Reflect(shootRay.direction, shootHit.normal); // 增加一个新的点,这样线就会往折射方向延申 lineRenderer.positionCount += 1; lineRenderer.SetPosition(preIndex + 1, reflectVector * 100); // 重新设置碰撞射线的起点和方向 shootRay.origin = shootHit.point; shootRay.direction = reflectVector; } }