Пример #1
0
        private IEnumerator Fly()
        {
            float t               = 0;
            float maxFlyTime      = 10f;
            var   prevFlyPosition = transform.transform.position;

            while (maxFlyTime > t)
            {
                yield return(null);

                t += Time.deltaTime;
                transform.position = trajectory.CalculatePointForTime(t);

                // Проверяем через рейкаст на столкновение снаряда с поверхностью
                var        lastPositionToNewPosition = transform.position - prevFlyPosition;
                RaycastHit hitInfo     = default;
                var        hitHappened = Physics.Raycast(
                    prevFlyPosition,
                    lastPositionToNewPosition,
                    out hitInfo,
                    lastPositionToNewPosition.magnitude,
                    GameFieldGlobalConsts.FIELD_SURFACE_PHYSIC_LAYER);
                if (hitHappened &&
                    hitInfo.collider != null &&
                    hitInfo.collider.tag == GameFieldGlobalConsts.FIELD_SURFACE_TAG)
                {
                    break;
                }
                prevFlyPosition = transform.position;
            }

            // Взрываем снаряд
            yield return(new WaitForSeconds(view?.PlayAnim(AnimationConsts.DEATH) ?? 0));

            Destroy(gameObject);
        }