Exemplo n.º 1
0
        /// <summary>
        /// Server only: check for collectibles colliding with the zone.
        /// Possible collision are defined in the Physics Matrix.
        /// </summary>
        public void OnTriggerEnter(Collider col)
        {
            if (!PhotonNetwork.IsMasterClient)
            {
                return;
            }

            //the game is already over so don't do anything
            if (GameManager.GetInstance().IsGameOver())
            {
                return;
            }

            //check for the required object
            //continue, if it is not assigned to begin with
            if (requireObject != null)
            {
                //the required object is not instantiated
                if (requireObject.obj == null)
                {
                    return;
                }

                //the required object either does not have a CollectibleTeam component,
                //is still being carried around or not yet at back at the spawn position
                CollectibleTeam colReq = requireObject.obj.GetComponent <CollectibleTeam>();
                if (colReq == null || colReq.carrierId >= 0 ||
                    colReq.transform.position != requireObject.transform.position)
                {
                    return;
                }
            }

            CollectibleTeam colOther = col.gameObject.GetComponent <CollectibleTeam>();

            //a team item, which is not our own, has been brought to this zone
            if (colOther != null && colOther.teamIndex != teamIndex)
            {
                if (scoreClip)
                {
                    AudioManager.Play3D(scoreClip, transform.position);
                }

                //add points for this score type to the correct team
                GameManager.GetInstance().AddScore(ScoreType.Capture, teamIndex);
                //the maximum score has been reached now
                if (GameManager.GetInstance().IsGameOver())
                {
                    //close room for joining players
                    PhotonNetwork.CurrentRoom.IsOpen = false;
                    //tell all clients the winning team
                    GameManager.GetInstance().localPlayer.photonView.RPC("RpcGameOver", RpcTarget.All, (byte)teamIndex);
                    return;
                }

                //remove network messages about the Collectible since it is about to get destroyed
                PhotonNetwork.RemoveRPCs(colOther.spawner.photonView);
                colOther.spawner.photonView.RPC("Destroy", RpcTarget.All);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Server only: check for collectibles colliding with the zone.
        /// Possible collision are defined in the Physics Matrix.
        /// </summary>
        public void OnTriggerEnter(Collider col)
        {
            if (!isServer)
            {
                return;
            }

            //the game is already over so don't do anything
            if (GameManager.GetInstance().IsGameOver())
            {
                return;
            }

            //check for the required object
            //continue, if it is not assigned to begin with
            if (requireObject != null)
            {
                //the required object is not instantiated
                if (requireObject.obj == null)
                {
                    return;
                }

                //the required object either does not have a CollectibleTeam component,
                //is still being carried around or not yet at back at the spawn position
                CollectibleTeam colReq = requireObject.obj.GetComponent <CollectibleTeam>();
                if (colReq == null || colReq.carrierId.Value > 0 ||
                    colReq.transform.position != requireObject.transform.position)
                {
                    return;
                }
            }

            CollectibleTeam colOther = col.gameObject.GetComponentInChildren <CollectibleTeam>();

            //a team item, which is not our own, has been brought to this zone
            if (colOther != null && colOther.teamIndex != teamIndex)
            {
                if (scoreClip)
                {
                    AudioManager.Play3D(scoreClip, transform.position);
                }

                //add points for this score type to the correct team
                GameManager.GetInstance().AddScore(ScoreType.Capture, teamIndex);
                //the maximum score has been reached now
                if (GameManager.GetInstance().IsGameOver())
                {
                    //tell all clients the winning team
                    GameManager.GetInstance().localPlayer.RpcGameOver(teamIndex);
                    return;
                }

                //reset network messages about the Collectible since it is about to get destroyed
                int changedIndex = GameManager.GetInstance().AddBufferedCollectible(colOther.netId, colOther.spawner.transform.position, new NetworkInstanceId(0));
                GameManager.GetInstance().OnCollectibleStateChanged(SyncListCollectible.Operation.OP_DIRTY, changedIndex);
                colOther.spawner.Destroy();
            }
        }