Example #1
0
    void OnTriggerEnter(Collider other)
    {
        if (destroyed == false)
        {
            ShotSphere shot = other.attachedRigidbody.GetComponent <ShotSphere>();

            // did the rock get hit with a shot
            if (shot)
            {
                // does the shot have the shooter set so we can reward them
                if (shot.shooter)
                {
                    // did a player shoot us, give them some points
                    RocketSphere rocketPlayer = shot.shooter.GetComponent <RocketSphere>();
                    if (rocketPlayer)
                    {
                        rocketPlayer.points += points;
                    }

                    // did an AI shoot us, give them some points
                    RocketSphereAI rocketAI = shot.shooter.GetComponent <RocketSphereAI>();
                    if (rocketAI)
                    {
                        rocketAI.points += points;
                    }
                }
            }

            GameObject explosion = Instantiate(explosionPrefab, rock.transform.position, Quaternion.identity) as GameObject;
            NetworkServer.Spawn(explosion);

            destroyedRocks++;
            currentRocks--;

//            Debug.Log("OntriggerEnter Rocks " + currentRocks + " total " + totalRocks + " destoyed " + destroyedRocks);

            // let all the clients know the current rock counts for music
            // IMPORTANT!!!!, this must be called before the detroy or the rpc will never go out.
            rpcSetRockStats(currentRocks, totalRocks, destroyedRocks);

            destroyed = true;
            NetworkServer.Destroy(transform.gameObject);

            if (rockSpherePrefab)
            {
                for (int i = 0; i < pieces; i++)
                {
                    GameObject newRock = Instantiate(rockSpherePrefab, rock.transform.position, rock.transform.rotation) as GameObject;
                    NetworkServer.Spawn(newRock);
                }
            }
        }
    }
    void OnTriggerEnter(Collider other)
    {
        // Rocket is already destroyed, ignore
        if (!rocket.activeSelf)
        {
            return;
        }

        ShotSphere shot = other.attachedRigidbody.GetComponent <ShotSphere>();

        // did a shot hit us
        if (shot)
        {
            if (shot.shooter)
            {
                if (shot.shooter == transform.gameObject)
                {
                    // ignore getting hit with our own shots
                    return;
                }

                // did we get shot by another player, give them some points
                RocketSphere rocketPlayer = shot.shooter.GetComponent <RocketSphere>();
                if (rocketPlayer)
                {
                    rocketPlayer.points++;
                }

                // did we get shot by an AI player, give them some points
                RocketSphereAI rocketAI = shot.shooter.GetComponent <RocketSphereAI>();
                if (rocketAI)
                {
                    rocketAI.points++;
                }
            }
        }

        // Spawn an explosion at player position on all clients
        GameObject explosion = Instantiate(explosionPrefab, rocket.transform.position, Quaternion.identity) as GameObject;

        NetworkServer.Spawn(explosion);

        // deactivate the ship on all clients
        RpcMySetActive(false, Quaternion.identity, false);

        // spawn a new ship, do this on the local player client and it will re-enable on all clients
        rpcSpawnShipDelay();
    }
Example #3
0
    void OnTriggerEnter(Collider other)
    {
        ShotSphere shot = other.attachedRigidbody.GetComponent <ShotSphere>();

        // did a shot hit us
        if (shot)
        {
            // make sure the shooter still exists
            if (shot.shooter)
            {
                // ignore our own shots
                if (shot.shooter == transform.gameObject)
                {
                    return;
                }

                // did a player shoot us, give them some points
                RocketSphere playerShooter = shot.shooter.GetComponent <RocketSphere>();
                if (playerShooter)
                {
                    playerShooter.points += 2;
                }

                // did a AI shoot us, give them some points
                RocketSphereAI rocketShooterAI = shot.shooter.GetComponent <RocketSphereAI>();
                if (rocketShooterAI)
                {
                    rocketShooterAI.points += 2;
                }
            }
        }

        // Spawn an explosion at rocket position on all clients
        GameObject explosion = Instantiate(explosionPrefab, rocket.transform.position, Quaternion.identity) as GameObject;

        NetworkServer.Spawn(explosion);

        // let the AI know we finished
        transform.gameObject.GetComponent <RocketAIAgent>().EpisodeEndBad();

        // destory the ship on all clients
        destroyed = true;
        NetworkServer.Destroy(transform.gameObject);
    }