예제 #1
0
        /// <summary>
        /// MonoBehaviour method called on GameObject by Unity on every frame.
        /// </summary>
        void Update()
        {
            if (PhotonNetwork.isMasterClient)
            {
                if (GameObject.FindGameObjectsWithTag("Pellet").Length == 0)
                {
                    GameManager.addPellets();
                }
            }

            if (photonView.isMine)
            {
                //Check for power mode
                if (inPowerMode)
                {
                    if (powerModeCtr < 8f)
                    {
                        powerModeCtr += Time.deltaTime;
                        photonView.RPC("InPowerMode", PhotonTargets.All, GetComponent <PhotonView>().viewID);
                        moveSpeed     = POWER_MOVE_SPEED;
                        rotationSpeed = POWER_ROTATION_SPEED;
                    }
                    else
                    {
                        inPowerMode  = false;
                        powerModeCtr = 0f;
                        photonView.RPC("FinishedPowerMode", PhotonTargets.All, GetComponent <PhotonView>().viewID);
                        moveSpeed     = NORMAL_MOVE_SPEED;
                        rotationSpeed = NORMAL_ROTATION_SPEED;
                    }
                }

                ProcessInputs();
            }
        }
예제 #2
0
        /// <summary>
        /// MonoBehaviour method called when the Collider 'other' enters the trigger.
        /// If it is another player, both should bounce back
        /// </summary>
        void OnTriggerEnter(Collider other)
        {
            //Only care about local player
            if (!photonView.isMine)
            {
                return;
            }

            if (other.gameObject.tag == "Pacman")
            {
                if (inPowerMode)
                {
                    photonView.RPC("KickPlayer", PhotonTargets.MasterClient, other.gameObject.GetComponent <PhotonView>().owner.ID);
                    isAligning = true;
                    alignPlayer();
                }
                else
                {
                    recentlyCollided    = true;
                    recentlyCollidedCtr = 0;

                    Quaternion rotation = Quaternion.Euler(new Vector3(0, GetComponent <Rigidbody>().rotation.eulerAngles.y - 180f, 0));
                    GetComponent <Rigidbody>().rotation = rotation;

                    GetComponent <Rigidbody>().MovePosition(transform.position + transform.forward * Time.deltaTime * 5);
                }
            }
            else if (other.gameObject.tag == "Ghost")
            {
                if (inPowerMode)
                {
                    other.gameObject.transform.position = new Vector3(0.5f, 0, 0.5f);
                    isAligning = true;
                    alignPlayer();
                }
                else
                {
                    this.gameObject.transform.position = GameManager.startingPositions[playerNumber];
                    this.gameObject.transform.rotation = Quaternion.Euler(GameManager.startingRotations[playerNumber]);

                    PhotonNetwork.player.AddScore(-25);
                    inPowerMode = false;
                }
            }
            else if (other.gameObject.tag == "Fruit")
            {
                photonView.RPC("FruitEaten", PhotonTargets.MasterClient, other.GetComponent <PhotonView>().viewID);

                //Destroy all previous pellets
                foreach (GameObject pellet in GameObject.FindGameObjectsWithTag("Pellet"))
                {
                    PhotonNetwork.Destroy(pellet.GetComponent <PhotonView>());
                }

                //Spawn new pellets
                GameManager.addPellets();
            }

            else if (other.gameObject.tag == "PowerPellet")
            {
                photonView.RPC("PowerPelletEaten", PhotonTargets.MasterClient, other.GetComponent <PhotonView>().viewID);

                //Destroy all previous powerPellets
                foreach (GameObject powerPellet in GameObject.FindGameObjectsWithTag("PowerPellet"))
                {
                    PhotonNetwork.Destroy(powerPellet.GetComponent <PhotonView>());
                }

                //Power mode
                inPowerMode = true;
            }

            //Pellet collision: Pellet removed from map, player score increases
            else if (other.gameObject.tag == "Pellet")
            {
                if (pelletBeingDestroyed == null || pelletBeingDestroyed != other.gameObject)
                {
                    photonView.RPC("PelletEaten", PhotonTargets.MasterClient, other.GetComponent <PhotonView>().viewID);

                    PhotonNetwork.player.AddScore(1);

                    pelletBeingDestroyed = other.gameObject;

                    //Update score on UI
                    photonView.RPC("UpdateScore", PhotonTargets.All, GameManager.playerScoreTextBoxPhotonIDs[playerNumber], PhotonNetwork.player.NickName + ": " + PhotonNetwork.player.GetScore());
                    //PhotonView.Find(GameManager.playerScoreTextBoxPhotonIDs[playerNumber]).GetComponent<Text>().text = PhotonNetwork.player.NickName + ": " + PhotonNetwork.player.GetScore();
                }
            }
        }