- Home /
How to make that when someone presses a button the function of the button happens to everyone. Photon Pun
Hi!
I am making a multiplayer game using Unity and Photon for the first time and I have a start game button in my game and when someone presses that button I would want the StartGame function to happen to everyone in the room so that enemies can start spawning. But right now when someone presses the button the StartGame function happens only to him. What should I do to make that when someone presses the button the game starts to everyone.
This is my start game script at the moment:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class StartGameScript : MonoBehaviour
{
public static bool gameIsStarted;
public GameObject StartButton;
public Button SpawnEnemyButton;
private void Start()
{
gameIsStarted = false;
}
public void StartGame()
{
gameIsStarted = true;
StartButton.SetActive(false);
SpawnEnemyButton.interactable = true;
}
}
I'd greatly appreciate any help (and sorry for my bad english).
Answer by Captain_Pineapple · Jul 18, 2021 at 02:36 PM
Hey there,
in general you should read into RPC
. (Remote Procedure Call) This is the basic thing you need to do anything with PUN.
PLEASE MAKE SURE TO READ THIS DOCUMENTATION: PUN RPC DOCUMENTATION This will be important to understand the basics of PUN.
Then you need to have a Photon View for each player on this object.
To call a function for all players you need to add the [PunRPC] tag to your function:
[PunRPC]
public void StartGame()
{
//do whatever has to happen here.
}
And then you can use this as followed:
photonView.RPC("StartGame", RPCTargets.All);
Your answer
![](https://koobas.hobune.stream/wayback/20220613040501im_/https://answers.unity.com/themes/thub/images/avi.jpg)