Exemple #1
0
 public override void HandleCollision(GameObject gameObject, CollisionDirection collisionDirection)
 {
     if (gameObject is Portal)
     {
         if (collisionDirection == CollisionDirection.None)
         {
             this.HandleReadyToBeShot();
         }
     }
     else if (!(gameObject is Block))
     {
         PortalPhysics.TeleportObject(this.portal, gameObject);
     }
 }
    private void Fire(Polarity polarity)
    {
        Color      color = polarity == Polarity.Left ? LeftPortalColor : RightPortalColor;
        Ray        ray   = new Ray(_camera.transform.position, _camera.transform.forward);
        RaycastHit hit;
        bool       hitWall;

        if (_shootThroughPortals)
        {
            hitWall = PortalPhysics.Raycast(ray, out hit, Mathf.Infinity, _canHit, QueryTriggerInteraction.Collide);
        }
        else
        {
            int mask = _canHit | PortalPhysics.PortalLayerMask;
            hitWall = Physics.Raycast(ray, out hit, Mathf.Infinity, mask, QueryTriggerInteraction.Collide);
        }

        if (hitWall)
        {
            Portal portal = hit.collider.GetComponent <Portal>();
            if (portal)
            {
                WavePortalOverTime(portal, hit.point, _portalWaveAmplitude, _portalWaveDuration);
            }
            else
            {
                bool spawnedPortal = TrySpawnPortal(polarity, hit);
                if (!spawnedPortal)
                {
                    SpawnSplashParticles(hit.point, hit.normal, color);
                }
            }
        }

        // Spawn a bullet that will auto-destroy itself after it travels a certain distance
        SpawnBullet(_bulletPrefab, _camera.transform.position + _camera.transform.forward * _bulletSpawnOffset, _camera.transform.forward, hit.distance, color);
    }