Esempio n. 1
0
    /** Only the shooter's instance of the projectile has a collider */
    void OnCollisionEnter(Collision col)
    {
        if (destroyed)
        {
            return;            // Don' process more than one collision... hope this helps...?
        }
        // The first thing a projectile hits should destroy it (unless it's the shooter)
        GameObject obj = col.gameObject;

        // Check if it's a player. If it is, filter out the shooter.
        PlayerMovementController pmc = obj.GetComponent <PlayerMovementController>();
        bool hitPlayer = (pmc != null);

        if (hitPlayer)
        {
            // Is this the shooter?
            if (Tools.NullToEmptyString(obj.GetComponent <PhotonView>().Owner.UserId) == shooterId)
            {
                return;
            }
        }

        // Did we hit a pillar?
        PillarBehaviour pillar    = obj.GetComponent <PillarBehaviour>();
        bool            hitPillar = (pillar != null);

        if (hitPillar)
        {
            // TODO: One day I'll find out why objects are suddenly null...
            if (pillarCtrl == null)
            {
                InitControllers();
            }
            pillarCtrl.BroadcastHitPillar(pillar.id);
        }

        // Is this projectile seeking a targetable player? If so we need to tell him we're not seeking him anymore
        if (lockedOn)
        {
            target.BroadcastBecameUntargeted(shooterId);
        }

        // Did we hit the sun?
        SunController sun = obj.GetComponent <SunController>();

        if (sun != null)
        {
            sun.BroadcastHit(shooterId);
        }

        // In any case, all collisions destroy the projectile
        explosionCtrl.BroadcastExplosion(transform.position, shooterId, false);
        projectileCtrl.BroadcastDestroyProjectile(projectileId);
        destroyed = true;
    }
 void TriggerExplosions()
 {
     // We're in RPC context here (someone broadcasted a sun hit). Only broadcast an explosion if we're the shooter
     if (shooterId != Tools.NullToEmptyString(PhotonNetwork.LocalPlayer.UserId))
     {
         return;
     }
     // Trigger explosions on all locations
     foreach (var position in explosionPositions)
     {
         explosionCtrl.BroadcastExplosion(position, shooterId, true);
     }
     // Trigger pillar extension on hit pillar
     pillarCtrl.BroadcastHitPillar(hitPillarId);
 }