Hello,
I made a pong game for 2 people (each controlling 2 platforms) and it works. However, if there is only 1 person there’s not much going on so I wanted to implement a simple AI. The AI works great when there is one person but I have a problem when there are 2 people. I tried using various IDs, and I tried to use the user count which I thought would work. But when I tested for 2 players the pong platforms for the second player froze.
so I used
void Update() {
if (NuitrackManager.Users.Current != null && ControllerUser.Skeleton != null) {
if (ControllerUser.ID == 2) {
if (!GameObject.Find("PlayerLeft").transform.GetChild(0).gameObject.activeSelf) {
GameObject.Find("AI1").transform.GetChild(0).gameObject.SetActive(true);
GameObject.Find("AI1").transform.GetChild(1).gameObject.SetActive(true);
}
else {
GameObject.Find("AI1").transform.GetChild(0).gameObject.SetActive(false);
GameObject.Find("AI1").transform.GetChild(1).gameObject.SetActive(false);
}
GameObject.Find("AI").transform.GetChild(0).gameObject.SetActive(false);
GameObject.Find("AI").transform.GetChild(1).gameObject.SetActive(false);
GameObject.Find("PlayerRight").transform.GetChild(0).gameObject.SetActive(true);
GameObject.Find("PlayerRight").transform.GetChild(1).gameObject.SetActive(true);
}
else if (NuitrackManager.UsersList.Count == 1) {
if(ControllerUser.ID == 1) {
GameObject.Find("PlayerLeft").transform.GetChild(0).gameObject.SetActive(true);
GameObject.Find("PlayerLeft").transform.GetChild(1).gameObject.SetActive(true);
GameObject.Find("PlayerRight").transform.GetChild(0).gameObject.SetActive(false);
GameObject.Find("PlayerRight").transform.GetChild(1).gameObject.SetActive(false);
GameObject.Find("AI1").transform.GetChild(0).gameObject.SetActive(false);
GameObject.Find("AI1").transform.GetChild(1).gameObject.SetActive(false);
GameObject.Find("AI").transform.GetChild(0).gameObject.SetActive(true);
GameObject.Find("AI").transform.GetChild(1).gameObject.SetActive(true);
}
else if (ControllerUser.ID == 2) {
GameObject.Find("PlayerLeft").transform.GetChild(0).gameObject.SetActive(false);
GameObject.Find("PlayerLeft").transform.GetChild(1).gameObject.SetActive(false);
GameObject.Find("PlayerRight").transform.GetChild(0).gameObject.SetActive(true);
GameObject.Find("PlayerRight").transform.GetChild(1).gameObject.SetActive(true);
GameObject.Find("AI1").transform.GetChild(0).gameObject.SetActive(true);
GameObject.Find("AI1").transform.GetChild(1).gameObject.SetActive(true);
GameObject.Find("AI").transform.GetChild(0).gameObject.SetActive(false);
GameObject.Find("AI").transform.GetChild(1).gameObject.SetActive(false);
}
}
}
}
In the first if statement I used ControllerUserID == 2 just for testing and it also did not work. Then again the else if statement also does not work how I wanted with 2 people as NuitrackManager.UsersList.Count doesn’t return the number of detected people, rather it was always 1 whether there were 1 or 2 people. I know I also tried other Count methods but that too did not work. I’m sure it’s something simple but I’m stuck, so any insight would be much appreciated.
EDIT: A followup
In the first if statement I used
NuitrackManager.Users.Count == 2
and it worked as it detected 1 or 2 people, but only in the editor. When I made a build that no longer worked for some reason - I am now also running on a license if that makes any difference.