Ejemplo n.º 1
0
        public void CheckRaycast(ref Transform transform, ref WorldMovement Movement, ref IBulletBehaviour bulletBehaviour)
        {
            OutOfRange = false;

            if ((RayDistance > 0f) && !IsHit && !IsShowHit)
            {
                transform.position = Movement.Position;
                OutOfRange         = Vector3.Distance(Movement.Position, InitPosition) > ShotRange;
            }

            if (IsHit || OutOfRange || IsShowHit)
            {
                bulletBehaviour.BulletFinish();
            }
            else
            {
                mRay    = bulletBehaviour.Ray;
                mRayHit = bulletBehaviour.RayHit;
                bool isHit = Utils.Raycast(Movement.Position, Movement.MoveDirection, out mRay, out mRayHit, RayDistance, RayMask);
                if (isHit)
                {
                    bulletBehaviour.HitTarget = mRayHit.transform.gameObject;
                    GameObject hitTarget = bulletBehaviour.HitTarget;

                    int hitLayer = hitTarget.layer;
                    int id       = hitTarget.GetInstanceID();
                    DoHit(hitLayer, id, mRayHit.point, Movement.MoveDirection);
                    bulletBehaviour?.AfterDoHit(this);
                    if (!IsShowHit)
                    {
                        IsShowHit = true;
                        CommonBulletChecker?.CacheBulletData(this);//处理命中后的操作
                    }
                }
            }
        }