- Home /
Photon give priority to Canvas Input (Event System)
Hi I´m trying to learn how to make a first person multiplayer game game, and I have a problem, I have a menu which appears before I instantiate the player and I want to also be able to make it appear when a button is pressed.
My problem is that I can't interact with the menu since the player controller takes over, nor I know how to deactivate the player since there are multiple instances of it and it's created on runtime.
void Update(){ //Update is the only way I know to check if certain key is pressed
if (Input.GetKeyDown(KeyCode.Escape)){ //The key is Escape
bool estado=serverWindow.activeSelf; //I get if the options/server window is pressed
serverWindow.SetActive(!estado);//I activate/deactivate it
messagesWindow.SetActive (estado);//I deactivate the chat window since its not needed when the menu is in use
}
}
This is the code I use to activate the menu and deactivate the chat
https://www.youtube.com/watch?v=yb0XymjusBc
Here is a link to a less than 30s video showing my problem
Thank you for your time :)
Answer by Maurice_B · Jan 02, 2015 at 08:18 PM
to disable all the playercontrollers:
on the playercontroller script:
static boolean cancontrol = true; //or false?
void start(){
//whatever you have here
}
void Update (){
if (cancontrol){
//most code here
}
}
(This probably isnt perfect as i usually code in js but the principle is the same)
on the menu:
void Update(){ //Update is the only way I know to check if certain key is pressed
playercontrollerscriptnamehere.cancontrol = false;
if (Input.GetKeyDown(KeyCode.Escape)){ //The key is Escape
bool estado=serverWindow.activeSelf; //I get if the options/server window is pressed
serverWindow.SetActive(!estado);//I activate/deactivate it
messagesWindow.SetActive (estado);//I deactivate the chat window since its not needed when the menu is in use
//dont forget playercontrollerscriptnamehere.cancontrol =true when the menu is closed
}
}
Explanation: Static variables are the same on all instances of a script so you can controll them all at runtime. Good luck.
Maurice
Thanks for taking the time to answer my question, and sorry I realized I didn't explain what I needed properly. I know that's what I need to do, but I don't know how to access the controllerscript since I instantiate the player at runtime (photon.instantiate) and multiple instances of players are in the game. I tried finding the player by tag but all players have the same tag.
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape)){
bool state=serverWindow.activeSelf;
GameObject player = GameObject.FindGameObjectsWithTag("Player");
player.GetComponent<controller>().enabled=state;
serverWindow.SetActive(!state);
messagesWindow.SetActive (state);
}
I know you can do .Is$$anonymous$$ine when in photon, but I don't know how to use it properly, can I just call it in a gameobject? if so how?
Thanks again