- Home /
simple networked int script simply dont work.
This have made me scratch my beard for hours.
This is how i want it to work:
map is set to 0.
if player preses button 1,2,3 the right chosebutton void get triggerd and changes the map int.
when player presses space the right [command] work correctly.
if player press space before choses a map int , the "Oops, you have not selected a map" Debug is called.
ATM its no errors, just chaos, the funktions get run out of nothin and the " if map == x" dosnt seen to work.
public GameObject smm; public int map = 0;
void Start()
{
Instantiate(smm);
map = 0;
}
void Update()
{
if (!isLocalPlayer)
{
return;
}
if (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("space pressed");
TestIfCanStartMatch();
}
}
//THIS IS THE MAP SELECTING FUNKTIONS
public void chosemap1()
{
map = 1;
Debug.Log(map);
}
public void chosemap2()
{
map = 2;
Debug.Log(map);
}
public void chosemap3()
{
map = 3;
Debug.Log(map);
}
//THIS IS THE MAP SELECTING FUNKTIONS
void TestIfCanStartMatch()
{
if(map == 1)
{
Debug.Log("Oops, you have not selected a map!");
}
if(map != 0)
{
Debug.Log("Iniziating match....");
Inizatematch();
}
}
void Inizatematch()
{
CmdSpawnMap(map);
}
[Command]
void CmdSpawnMap(int mapnr)
{
if(mapnr == 1)
{
Debug.Log("Spawning map 1");
}
if (mapnr == 2)
{
Debug.Log("Spawning map 1");
}
if (mapnr == 3)
{
Debug.Log("Spawning map 1");
}
}
}
Answer by toddisarockstar · Jun 12, 2018 at 12:52 AM
are you looking for something like this?
public int select = 0;
void Update () {
if (Input.inputString.Length == 1) {
int.TryParse (Input.inputString, out select);
if (select > 0 && select < 4) {
print ("selected map #" + select);} else {select = 0;}}
if (Input.GetKeyDown(KeyCode.Space))
{if (select > 0) {loadamap(select);}else{
print ("<color=red>No map selected</color>");}}}
void loadamap(int map){
print ("User wants to load map#" + map+" !!!");
}
Your answer
Follow this Question
Related Questions
How to properly send data over TcpClient? 0 Answers
Can I use not LAN IP in Network Manager? 0 Answers
UNET Direct IP Connection not working 0 Answers
Animation & sound over network 1 Answer
Syncing terrain over Network 0 Answers